我的[$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
然后是我的角度代码
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) {
...
}]);
答案 0 :(得分:1)
好像你没有一个名为config
的提供商,以便向控制器注入,
app.controller('navController', ['$scope', 'config', 'sharedProperties', function ($scope, config, sharedProperties) {
删除正在注入的config
,它会起作用。如,
app.controller('navController', ['$scope', 'sharedProperties', function ($scope, sharedProperties) {
或者您必须定义名为config
的提供程序。
如果你期望var config
会注入控制器,实际上它不会注入。你需要一些提供者类型来注入service
,factory
,value
.. ..