Surprised to see why the angularjs promise is not resolved multiple times using $interval
service. Below is my code. The variable i
is incremented multiple times, however the promise is resolved only once.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, myService) {
myService.then(function(result) {
$scope.i = result;
});
});
app.factory('myService', function($interval, $q) {
var deferred = $q.defer();
var i = 0;
$interval(function() {
i += 1;
deferred.resolve(i);
}, 2000);
return deferred.promise;
});