我試圖編寫一個簡單的服務後面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
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:2862
createInjector/instanceCache.$injector<@http://localhost:8080/tm-webapp/resources/lib/angular.js:2739
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:2862
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:2880
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:2914
@http://localhost:8080/tm-webapp/resources/lib/angular.js:4805
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:14198
[email protected]://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/[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:6846
qFactory/defer/deferred.promise.then/[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:6846
qFactory/ref/<.then/<@http://localhost:8080/tm-webapp/resources/lib/angular.js:6883
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:8057
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:7922
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:8143
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:9170
[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:9333
createHttpBackend/</[email protected]://localhost:8080/tm-webapp/resources/lib/angular.js:9304
我是什麼做錯了?
請你的第二個片段澄清'Controllers'。它是如何定義的? –
Controllers.controller應該可能是projectModule.controller – AlwaysALearner
@stevuu我已經添加了它。 「var Controllers = angular.module('fixedTeam',[]); – Shahzeb