Organizational Research By

Surprising Reserch Topic

angularjs promise executes only once

angularjs promise executes only once  using -'angularjs'

Is any way that $promise can execute multiple times or any alternate in angular.

Refer below code.
Sample Code:-

promise.then(function(greeting) {
  alert('Success: ' + greeting);


if () {
     resolve('Hello, ' + name + '!');
} else {
     reject('Greeting ' + name + ' is not allowed.');


asked Oct 13, 2015 by android_master
0 votes

Related Hot Questions

3 Answers

0 votes

The contract of a promise is that it will only ever resolve once, and honestly I can't really imagine any scenarios where it makes sense for it to execute more than once. After a promise has resolved, any subsequent calls to then will be invoked upon the next event loop tick as the value of the promise has already been resolved and will be cached.

This seems like an XY problem. Could you explain what you are trying to do in more detail?

answered Oct 13, 2015 by gauravg.gwl
0 votes

You can go through this forum where Thomas has told how you can resolving a promise multiple times.

$rootScope.$apply( function() {
  deferred.resolve( incremented );
answered Oct 13, 2015 by kinnari
0 votes

You could probably use the notify callback

notify(value) - provides updates on the status of the promise's execution. This may be called multiple times before the promise is either resolved or rejected.

The following (untested) code should notify ten times with the numbers 1-10 and then resolve with the message "Done counting".

function countToTen() {
    return $q(function(resolve, reject, notify) {
        for (var counter=1; counter <= 10; counter++) {
            setTimeout(function() {
            }, 1000 * counter);
        setTimeout(function() { resolve("Done counting"); }, 10001);
answered Oct 13, 2015 by rajesh