I write some example code about $timeout service.
var myModule = angular.module('timerTest',[]);
myModule.controller('counting',function($scope,$timeout)
{
var timerObject;
var count =0;
var countTime = function()
{
count++;
console.log(count);
$scope.value = count;
timerObject = $timeout(countTime,1000);
};
$scope.startTimer = function()
{
console.log('timer start!');
$timeout(countTime,1000);
};
$scope.endTimer = function()
{
console.log('End Timer');
$timeout.cancel(timerObject);
};
});
In that code at countTime function, when I wrote
timerObject = > $timeout(countTime(),1000);
It calls countTime() very fast so It will make callstack overflow.
But when I wrote
timerObject = $timeout(countTime,1000);
It works perfectly. Is any different from that?