Recently, I've started working with Angular JS
on a game development project. One of the requirements is to call a function after a timeout. After some research, I found out about the $timeout
feature provided by AngularJS
, so I tried injecting it into the controller. However, for some reason, it doesn't seem to be working as expected. I'm not sure what's wrong or how to go about debugging this issue?
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);
}
}
Edit:
I have followed the suggestions from @STEVER but unfortunately, the issue persists.
Upon inspecting the console, I encountered the following error:
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