javascript - How to inject $http in ng-route templateUrl funcion? -
this question has answer here:
my web application has many views(templates) , there no static pattern composed templateurl route parameters. considering flexibility update routes, stores routing table in sql server , create restful web service retrieve&update route-template records. however, find no way call $http , $rootscope in angularjs during configuration phrase.
i understand .config happens before .run in angularjs. in configuration, can access constant , providers. since i'm using templateurl function, function body called @ run time. wondering if there's way inject $http , $rootscope in templateurl function executed @ run phrase...
angular.module('app', ['ngroute']).config(['$routeprovider', function ($routeprovider) { $routeprovider. when('/:param1/:param2/:param3', { templateurl: function(element){ // $http routing table restful api // store table $rootscope // table param1+param2+param3 key, template url return templateurlfromtable ; }}). otherwise({redirectto: '/'}); }])
i'm new angularjs, other suggestion welcome. also, please correct me if understanding wrong. thanks.
some alternatives dynamic routing discussed on thread:
other alternative solution render routing configuration dinamically on server side explained on article:
http://odetocode.com/blogs/scott/archive/2014/03/24/dynamic-routes-with-angularjs.aspx
Comments
Post a Comment