2013-08-01 74 views
1

我試圖編寫一個簡單的服務後面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 

我是什麼做錯了?

+0

請你的第二個片段澄清'Controllers'。它是如何定義的? –

+0

Controllers.controller應該可能是projectModule.controller – AlwaysALearner

+0

@stevuu我已經添加了它。 「var Controllers = angular.module('fixedTeam',[]); – Shahzeb

回答

5

需要添加相關模塊:

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

它給了我現在「 錯誤:沒有模塊:projectModule [打破這個錯誤] \t 拋錯誤(‘無模塊:’+名); – Shahzeb

+0

檢查編輯的答案。感謝@Oliver Kovacs – AlwaysALearner

+0

非常感謝您的時間。有效 – Shahzeb

相關問題