angularjs - using resolve in app.config -


i'm using angularjs's resolve in config load values needed controller, before controller loaded. code i'm using test logic

(function () {      "use strict";      var app = angular.module("lab1app", ["ngroute"]);      app.config(["$routeprovider", function ($routeprovider) {         $routeprovider.when("/", {             templateurl: "/views/view1.html"         }).when("/view2", {             templateurl: "views/view2.html",             controller: "secondcontroller",             resolve: {                 name: ["dropdownservice", function (dropdownsvc) {                     return dropdownsvc.loadname(5);                 }]             }         }).otherwise({             template: "don't have routes associated this"         });     }]);      app.controller("maincontroller", [ "$scope", function ($scope) {      }]);      app.controller("secondcontroller", [ "$scope", "name", function ($scope, name) {         console.log(name);     }]);      app.constant("api", { url: "http://localhost:55339/api/dropdowns" });      app.factory("dropdownservice", ["api", "$http", "$q", function (api, $http, $q) {          return {             loadname: function (id) {                 console.log("im here");                 var deferred = $q.defer();                  $http.get(api.url + "/" + id)                     .success(function (result) {                         deferred.resolve(result);                     }).error(function (err, status) {                         deferred.reject("error: " + err + ", status: " + status);                     });                  return deferred.promise;             }         };     }]);  })(); 

now when run code i'm getting error:

error: [$injector:unpr] unknown provider: nameprovider <- name <- secondcontroller

although i'm getting name variable in controller, error being thrown.

could tell me doing wrong ?

i'm going venture guess somewhere, inside view2.html, have

ng-controller="secondcontroller" 

this second invocation of "secondcontroller" controller throws "unknown provider" error, because doesn't have resolve-d name.

to fix, remove ng-controller directive.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -