angularjs - dynamic template based on $routeProvider resolves -



angularjs - dynamic template based on $routeProvider resolves -

i've got url in application needs load 1 of 2 templates based on results of resolve call, so:

app.config(function($routeprovider) { $routeprovider. when('/someurl', { resolve: { somedata: function(dataservice) { var info = dataservice.loaddata(); // info has .type field determines template should loaded homecoming data; } }, templateurl: function(routeparams) { // homecoming path based on value of data.type in somedata resolve block } }) });

is there way me set templateurl based on what's returned somedata resolve?

so figured out how using ui-router - m59 pointing me @ it.

here's how you'd ui-router:

app.config(function($stateprovider) { $stateprovider .state('somestate' url: '/someurl', template: '<ui-view>', resolve: { somedata: function(dataservice) { var info = dataservice.loaddata(); // info has .type field determines template should loaded homecoming data; } }, controller: function($state, somedata) { $state.go('somestate.' + somedata.type); } }) .state('somestate.type1', { templateurl: 'sometemplate1.html', controller: 'type1controller' }) .state('somestate.type2', { templateurl: 'sometemplate2.html', controller: 'type2controller' }) });

there's parent state handles resolves, redirects kid states based on info gets. kid states don't have url, can't loaded directly.

angularjs angularjs-routing

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -