编写新的角度服务返回错误错误:未知的提供者

时间:2013-08-01 10:26:56

标签: angularjs

我正在尝试在this tutorial之后编写一个简单的服务。添加新服务的代码是:

'use strict';
var projectModule = angular.module('project',[]);
projectModule.factory('Team', function() {  
    return {
        thing : {
            x : 100
        }
    };
});

我的控制器代码是:

var Controllers = angular.module('fixedTeam',[]);
Controllers.controller('controller', function ($scope,$http,$location,Team) {
    $scope.getFixedTeam = function(){
        console.debug(Team.thing);
    }
});

加载视图时,出现以下错误:

Error: Unknown provider: TeamProvider <- Team
createInjector/providerInjector<@http://localhost:8080/tm-webapp/resources/lib/angular.js:2734
getService@http://localhost:8080/tm-webapp/resources/lib/angular.js:2862
createInjector/instanceCache.$injector<@http://localhost:8080/tm-webapp/resources/lib/angular.js:2739
getService@http://localhost:8080/tm-webapp/resources/lib/angular.js:2862
invoke@http://localhost:8080/tm-webapp/resources/lib/angular.js:2880
instantiate@http://localhost:8080/tm-webapp/resources/lib/angular.js:2914
@http://localhost:8080/tm-webapp/resources/lib/angular.js:4805
update@http://localhost:8080/tm-webapp/resources/lib/angular.js:14198
Scope.prototype.$broadcast@http://localhost:8080/tm-webapp/resources/lib/angular.js:8307
updateRoute/<@http://localhost:8080/tm-webapp/resources/lib/angular.js:7463
qFactory/defer/deferred.promise.then/wrappedCallback@http://localhost:8080/tm-webapp/resources/lib/angular.js:6846
qFactory/defer/deferred.promise.then/wrappedCallback@http://localhost:8080/tm-webapp/resources/lib/angular.js:6846
qFactory/ref/<.then/<@http://localhost:8080/tm-webapp/resources/lib/angular.js:6883
Scope.prototype.$eval@http://localhost:8080/tm-webapp/resources/lib/angular.js:8057 
Scope.prototype.$digest@http://localhost:8080/tm-webapp/resources/lib/angular.js:7922 
Scope.prototype.$apply@http://localhost:8080/tm-webapp/resources/lib/angular.js:8143 
done@http://localhost:8080/tm-webapp/resources/lib/angular.js:9170 
completeRequest@http://localhost:8080/tm-webapp/resources/lib/angular.js:9333 
createHttpBackend/</xhr.onreadystatechange@http://localhost:8080/tm-webapp/resources/lib/angular.js:9304 

我做错了什么?

1 个答案:

答案 0 :(得分:5)

需要添加依赖模块:

var Controllers = angular.module('fixedTeam',['project']);