I stumbled upon an interesting anomaly in AngularJS. Why do these sections exhibit different behaviors?
Working Timeout (alert after 8 seconds)
$scope.testfun = function(){
alert(2);
}
$scope.activate = function(h,m,s){
if(h != 0 || m != 0 || s != 0) $timeout($scope.testfun, 8000);
}
Non-Working Timeout (alert immediately)
$scope.testfun = function(){
alert(2);
}
$scope.activate = function(h,m,s){
if(h != 0 || m != 0 || s != 0) $timeout($scope.testfun(), 8000);
}
The distinction between $scope.testfun and $scope.testfun() is crucial.