2015-11-01 85 views
0

我在我的AngularJS應用程序中遇到了[$injector:unpr]錯誤。AngularJS注射器問題

我已經查看了錯誤爲解決問題提供的鏈接,可悲的是它沒有改變任何東西。所以我希望你們能夠看到我做錯了什麼。

首先從我的瀏覽器控制檯錯誤

Error: [$injector:unpr] http://errors.angularjs.org/1.4.7/$injector/unpr?p0=configProvider%20%3C-%20config%20%3C-%20navController 
    at Error (native) 
    at http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:6:416 
    at http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:40:409 
    at Object.d [as get] (http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:38:394) 
    at http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:40:483 
    at d (http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:38:394) 
    at Object.e [as invoke] (http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:39:161) 
    at P.instance (http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:80:207) 
    at K (http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:61:190) 
    at g (http://localhost:8080/simplanner/lib/Angular-1.4.7/angular.min.js:54:410) 

    (anonymous function) @ angular.min.js:107 
    (anonymous function) @ angular.min.js:80 
    n.$apply @ angular.min.js:133 
    (anonymous function) @ angular.min.js:20 
    e @ angular.min.js:39d @ angular.min.js:19 
    zc @ angular.min.js:20Zd @ angular.min.js:19 
    (anonymous function) @ angular.min.js:293 
    a @ angular.min.js:174Hf.c @ angular.min.js:35 


然後ofcourse我的角碼

var config = { 
    ... 
}; 

var app = angular.module('SimPlannerApp', [ 
     'ui.router', 
     'ui.bootstrap' 
     ]); 

app.filter('capitalize', function() { 
    ... 
}) 
.filter('datetime', function ($filter) { 
    ... 
}); 

app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) { 
    var urlBase = '/' + config.IISProjectName + '/'; 

    $stateProvider 
     .state('login', { 
      url: "/login", 
      templateUrl: urlBase + 'views/login.html', 
      controller: 'loginController' 
     }) 
     .state('view', { 
      url: '/view/:view', 
      templateUrl: urlBase + 'views/view.html', 
      controller: 'viewController', 
      resolve: { 
       view: function ($stateParams) { 

        ... 

       } 
      } 
     }) 
     .state('404', { 
      url: '{path:.*}', 
      templateUrl: urlBase + '/views/404.html', 
      controller: 'errorController' 
     }); 
}); 

app.factory('sharedProperties', function() { 

    ... 

}); 

app.factory('socketService', function() { 

    ... 

}); 

app.controller('errorController', ['$scope', function ($scope) { 
    ... 
}]); 

app.controller('loginController', ['$scope', '$location', 'socketService', 'sharedProperties', function ($scope, $location, socketService, sharedProperties) { 
    ... 
}]); 

app.controller('navController', ['$scope', 'config', 'sharedProperties', function ($scope, config, sharedProperties) { 
    ... 
}]); 

app.controller('viewController', ['$scope', '$state', '$interval', 'view', 'socketService', function ($scope, $state, $interval, view, socketService) { 
    ... 
}]); 

回答

1

好像你沒有一個供應商稱爲config爲了注入輸入到控制器中,

app.controller('navController', ['$scope', 'config', 'sharedProperties', function ($scope, config, sharedProperties) { 

刪除config正在注入,它會工作。 as,

app.controller('navController', ['$scope', 'sharedProperties', function ($scope, sharedProperties) { 

或者您必須定義一個名爲config的提供者。

如果你期待var config會注入控制器,實際上它不會注入。你需要一些東西供應商類型注入像service,factory,value ..。

+0

謝謝^^驚人的是一雙清新的眼睛可以做什麼。我會在8分鐘內打勾這個解決方案 –

+0

oww :) yeaah oky很高興幫助你:) cheerz –