AngularJS错误:$injector:unpr 未知提供者
AngularJS错误:$injector:unpr 未知提供者
我正在尝试按照文档中工厂方法的示例来构建自己的服务。然而,我认为我做错了什么,因为我一直收到未知提供者的错误。这是我的应用程序代码,包括声明、配置和工厂定义。
编辑
我现在已经添加了所有的文件来帮助排除故障
编辑
错误的完整详细信息如下,问题似乎出在getSettings上,因为它在查找getSettingsProvider时找不到
Error: [$injector:unpr] http://errors.angularjs.org/1.2.16/$injector/unpr? p0=getSettingsProvider%20%3C-%20getSettings at Error (native) at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:6:450 at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:35:431 at Object.c [as get] (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:13) at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:35:499 at c (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:13) at d (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:230) at Object.instantiate (http://localhost/sw/selfservice/bower_components/angular/angular.min.js:34:394) at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:66:112 at http://localhost/sw/selfservice/bower_components/angular/angular.min.js:53:14 angular.js:9778 (anonymous function) angular.js:9778 (anonymous function) angular.js:7216 h.$apply angular.js:12512 (anonymous function) angular.js:1382 d angular.js:3869 $b.c angular.js:1380 $b angular.js:1394 Wc angular.js:1307 (anonymous function) angular.js:21459 a angular.js:2509 (anonymous function) angular.js:2780 q angular.js:330 c
这是我目前在我的应用程序中的所有文件
app.JS
//初始化angular模块包括路由依赖项 var app = angular.module("selfservice", ['ngRoute']); app.config(function ($routeProvider) { $routeProvider .when('/', { templateUrl:"partials/login.html", controller:"login" }); }); app.factory('getSettings', ['$http', '$q', function($http, $q) { return function (type) { var q = $q.defer(); $http.get('models/settings.json').success(function (data) { q.resolve(function() { var settings = jQuery.parseJSON(data); return settings[type]; }); }); return q.promise; }; }]);
以下是我在控制器中如何使用此服务
controller.JS
app.controller("globalControl", ['$scope','getSettings', function ($scope,getSettings) { var loadSettings = getSettings('global'); loadSettings.then(function(val) { $scope.settings = val; }); }]); app.controller("login", ['$scope', function ($scope) { return "" }]);
directives.js
app.directive('watchResize', function(){ return { restrict: 'M', link: function(scope, elem, attr) { scope.spacer = (window.innerWidth < 1025) ? '' : 'large-3'; scope.button = (window.innerWidth < 1025) ? '' : 'large-6'; angular.element(window).on('resize', function(){ scope.$apply(function(){ scope.spacer = (window.innerWidth < 1025) ? '' : 'large-3'; scope.button = (window.innerWidth < 1025) ? '' : 'large-6'; }); }); } }; });
如果相关的话,这是HTML
{{settings.title}}
有人可以指点我正确的方向吗?我已经尽力按照文档进行操作,浏览了SO上的大部分相关问题,但更深入一些,对我来说更难理解。这是我第一次创建服务。