Dynamically generate templateURL

I am trying to generate templatURL dynamically. I am using angularjs ui-routing

my routing function:

}).state('error',{
    url: '/:locale/office-profile/',
    templateUrl: function(obj) {
        return 'partials/error-' + obj.locale + '.html';
    }

      

I read other stackoverflow answers where they said they use a function like this. I am trying to get obj.locale to populate dynamically. I tried using $ stateParams.locale as I thought the url already has a locale, but that didn't work either.

When I do console.log (obj) it prints "Object: {locale: null}" and hence the template page cannot be loaded.

Please advise what I should do to achieve this. Thank you.

+3
javascript angularjs angularjs-routing


source to share


No one has answered this question yet

Check out similar questions:

2284
How can I combine properties of two JavaScript objects dynamically?
1799
Generating random integers in JavaScript within a specific range?
1678
Binding events to dynamically created elements?
1597
Generating a random number between two numbers in JavaScript
1427
Generate random strings / characters in JavaScript
2
Route provider cannot access controller definitions
2
Using Dynamic templateUrl for links built at runtime
1
angularjs, use function in routing like templateUrl
0
Angular JS V1.4.7 template directiveUrl dynamic path
0
AngularJS - How to get TemplateUrl from controller?



All Articles
Loading...
X
Show
Funny
Dev
Pics