所以我創建了一個dataService.j包含以下內容:定製服務未加載,就這麼簡單,我可以把它
angular.module('dataService', [])
.service('gameDataService', function() {
var _gameData = {
loggedIn: "false",
gameJoined:"false",
tableFull: "false",
username: "",
tableInfo: {},
atTable: "",
numJoined: 0,
userNames: [],
numPlayers: _.range(2,7),
numOfRuns: _.range(1,11)
};
this.gameData = _gameData;
return gameData;
});
然後,我有我的控制器模塊:
var client = angular.module('ui_client_ctrl' ,['ui_IO','dataService']);
client.controller('ClientController', function ($rootScope, $scope,gameDataService) {
$scope.gData = gameDataService.gameData;
console.log(gData);
});
我收到以下消息:
angular.js:13236 ReferenceError: gameData is not defined
at new <anonymous> (dataService.js:18)
at Object.instantiate (angular.js:4619)
at Object.<anonymous> (angular.js:4459)
at Object.invoke (angular.js:4604)
at Object.$get (angular.js:4443)
at Object.invoke (angular.js:4604)
at angular.js:4403
at d (angular.js:4550)
at e (angular.js:4574)
at Object.invoke (angular.js:4596)
我看過很多這裏的例子,這應該工作...任何建議至於爲什麼這不是加載?
任何幫助,將不勝感激,
ž
你正在返回錯誤的對象。你可以返回'_gameData',或者更好'this.gameData'(它們共享相同的參考) –