0

For example, a page contains multiple controllers and directives each making separate $http request to populate their data.

Is there a global event we can subscribe to that will be triggered when Angular finishes calling all callbacks (i.e. after all $http requests are complete and all callbacks have been executed)?

Clay
  • 10,885
  • 5
  • 47
  • 44
  • This might help: http://stackoverflow.com/questions/21138388/angular-js-identify-an-digest-complete-event-and-removing-from-url-in-angular – lintmouse Sep 23 '15 at 19:21
  • 1
    you could use `$q.all` giving array of promises to it.. – Pankaj Parkar Sep 23 '15 at 19:22
  • not without grouping them yourself such as with `$q.all` . It has no way to know how many requests will be made or which ones relate to any others. There are also $httpInterceptors that can be used – charlietfl Sep 23 '15 at 19:24

1 Answers1

0

Turns out there is an undocumented angular service called $browser that accomplishes this and is used by protractor.

waitForAngular = function(el, angular, callback) {
  try {
    angular.element(el).injector().get('$browser').notifyWhenNoOutstandingRequests(callback);
  } catch (e) {
    callback(e);
  }
};

https://www.snip2code.com/Snippet/91565/Wait-until-angularjs-is-done-with-proces

Clay
  • 10,885
  • 5
  • 47
  • 44