我是Angular JS
的新手。正在开发一款游戏。其中一个需求是在超时时调用一个函数。在做研究时,我看到有$timeout
由AngularJS
提供,我必须将$timeout
注入到控制器中,我试图这样做。但由于某种原因,我不确定这似乎不起作用!或者我不知道如何调试?
var ObstacleApp = angular.module('ObstacleApp', [])
.controller('GameCtrl',function($scope,$timeout,game) {
$scope.game = game;
});
ObstacleApp.factory('game', function() {
var tileNames = ['true', 'false', 'true', 'false', 'true','true','true','false','true','true','true','false','true','true','true','true','true','true','true','true'];
return new Game(tileNames);
});
function Game(tileNames)
{
// omitted code
this.showOnClick = function()
{
// omitted code
$timeout(callOnTimeout,6000);
}
}
编辑: 我已经通过@STEVER提到的变化 - 但它似乎不起作用。
当我Inspect
控制台我看
Error: Unknown provider: $timeoutProvider <- $timeout
at Error (native)
at file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:2492:15
at Object.getService [as get] (file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:2620:39)
at file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:2497:45
at getService (file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:2620:39)
at invoke (file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:2650:13)
at Object.instantiate (file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:2677:23)
at file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:4354:24
at file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:3986:17
at forEach (file:///home/rakshith/Desktop/Obstaclegame/lib/angular/angular.js:118:20)(anonymous function) @ angular.js:5240
其中'Game'功能属于? –