javascript - Why cant use provider inside the angular config? -


i developing angular app.in app need add route handler following

1.listen /app/:appid route depending on appid parameter download files server server.

files looks this

appid | |-html |    | |    ->index.html | |-javascript      |      ->app.js 

html folder , java script folder may have several files.but index.html file there.

2.after downloading files, should create route handler following

/appview/appid 

which points index.html file downloaded.

i created request handler download files. require parameters following

localhost:port/requesthandler.ashx?appid=myappid 

request handler tested , confirmed functioning properly.files downloading app/apps/appid folder.

then created route.config.js following

var app = angular.module('app');  app.constant('routes', getroutes());   app.config(function ($provide) {      $provide.provider("dataprovider", function () {         return {             $get: function ($http,$q) {                 return {                     getdata: function (appid) {                         var defer = $q.defer();                         $http.get('requesthandler.ashx?appid=' + appid).success(function (data) {                              defer.resolve(data);                          });                         return defer.promise;                     }                 };             }         };     }); });  app.config(['$routeprovider', 'routes', 'dataprovider', routeconfigurator]);  function routeconfigurator($routeprovider, routes, dataprovider) {       routes.foreach(function (r) {         $routeprovider.when(r.url, r.config);     });      $routeprovider.when("/app/:appid", {         redirectto: function (routeparams, path, search) {             $routeprovider.when("/appview/" + routeparams.appid, {                 templateurl: 'app/apps/'+routeparams.appid+'/html/index.html',              });               dataprovider.getdata(routeparams.appid);              return "/appview/" + routeparams.appid;         }     });     $routeprovider.otherwise({ redirectto: '/dashboard' }); }   function getroutes() {     return [         {             url: '/dashboard',             config: {                 templateurl: 'app/dashboard/dashboard.html',                 title: 'dashboard',                 settings: {                     nav: 1,                     content: '<i class="fa fa-dashboard"></i> dashboard'                 }             }         }     ]; } 

when run code, app stopped , gives following error.

uncaught object localhost:6406/scripts/angular.js:3809 

that particular line in angular.js file says this.

throw $injectorminerr('modulerr', "failed instantiate module {0} due to:\n{1}", 

but when removed parameter 'dataprovider' second config, app runs properly. cant use dataprovider download files server.

after removing 'dataprovider' line looks this.

app.config(['$routeprovider', 'routes',  routeconfigurator]);  function routeconfigurator($routeprovider, routes) {.... 

can show me missing here?

you need suffix provider name 'provider' string.

app.config(['$routeprovider', 'routes', 'dataproviderprovider', routeconfigurator]);  function routeconfigurator($routeprovider, routes, dataproviderprovider) {  } 

notice dataprovider provider injected config function. injection done provider injector different regular instance injector, in instantiates , wires (injects) provider instances only.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -