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

Building Template Url Dynamically #2295

Closed
iliassays opened this issue Apr 4, 2013 · 4 comments
Closed

Building Template Url Dynamically #2295

iliassays opened this issue Apr 4, 2013 · 4 comments

Comments

@iliassays
Copy link

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: {} });
            }
@lrlopez
Copy link
Contributor

lrlopez commented Apr 4, 2013

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" })

@sebfie
Copy link

sebfie commented Aug 6, 2013

Is it not 1.1.2 instead of 1.2.2 ?

@lrlopez
Copy link
Contributor

lrlopez commented Aug 6, 2013

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

@Narretz
Copy link
Contributor

Narretz commented Dec 19, 2013

@petebacondarwin this one can be closed too

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants