Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Building Template Url Dynamically #2295

Closed

Description

@iliassays

Hi

See the $routeProvider config.
.when('/Feedback/Details/:id', { templateUrl: '/Feedback/Details/:id', controller: "TestRoute" })

I need to set id with template url dynamically. Is there any option? I do not want to do any Hack like creating a controller and set routeProvider or using ng-include.

Bellow is a option what we can think for parseRoute method. But i do not want to touch the library code.

function parseRoute() {
// Match a route
var params, match;
forEach(routes, function (route, path) {
if (!match && (params = switchRouteMatcher($location.path(), path))) {
match = inherit(route, {
params: extend({}, $location.search(), params),
pathParams: params
});

                        if ((route.templateUrl) && (/:/.test(route.templateUrl))) {
                            match.templateUrl = interpolate(route.templateUrl, params);
                        }
                        //remove cached template if params were substituted (rely on browser cache)
                        if (match.templateUrl != route.templateUrl) {
                            match.template = undefined;
                        }

                        match.$route = route;
                    }
                });
                // No route matched; fallback to "otherwise" route
                return match || routes[null] && inherit(routes[null], { params: {}, pathParams: {} });
            }

Activity

  1. lrlopez commented on Apr 4, 2013

    @lrlopez
    Contributor

    It's already supported, kinda of. Have a look into #1849. This is available since 1.2.2.

    .when('/Feedback/Details/:id', { templateUrl: function(elem, attr) {
        return '/Feedback/Details/'+attr.id;
    }, '/Feedback/Details/:id', controller: "TestRoute" })
  2. sebfie commented on Aug 6, 2013

    @sebfie

    Is it not 1.1.2 instead of 1.2.2 ?

  3. lrlopez commented on Aug 6, 2013

    @lrlopez
    Contributor

    Yeah, it was a typo :) 1.1.2 should be ok...

  4. Narretz commented on Dec 19, 2013

    @Narretz
    Contributor

    @petebacondarwin this one can be closed too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions