Short version: reply to the title. Thank you for your help.
The longer version: I started, because, as I believe, many n00bs do, with a little code, added a little, a bit, and ended up with everything in one huge controller.
So, I shared my functionality and had a bunch of smaller controllers.
Then I wanted them to communicate with each other, and I discovered services.
Then I read that the controllers should be lean and medium, and I started moving the logic from the controllers to the services.
Now I find some kind of old code that is being read
$scope.internetConnectionRetryTimer = $interval($scope.attemptInternetConnection, RECONNECT_ATTEMPT_FREQUENCY);
when moving to a service
this.internetConnectionRetryTimer = $interval(this.attemptInternetConnection, RECONNECT_ATTEMPT_FREQUENCY);
, the timer does not seem to work; either this or does not call the function upon expiration.
The same question as the short version: can I use $ interval in the service?
[Refresh] here is the code:
global vars SERVER - URL and var RECONNECT_ATTEMPT_FREQUENCY = 5 * 1000; // 5 seconds
this.attemptInternetConnection = function()
{
$interval.cancel(this.internetConnectionRetryTimer);
var params = '?action=test_connection&user=dummy';
$http.get(SERVER + params).
success(function()
{
$interval.cancel(this.internetConnectionRetryTimer);
$rootScope.$broadcast('internetIsAvailable');
})
.error(function(status)
{
this.internetConnectionRetryTimer = $interval(this.attemptInternetConnection, RECONNECT_ATTEMPT_FREQUENCY);
$rootScope.$broadcast('internetIsUnavailable');
});
};