Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Why does $http not actually make a http request until you leave the current digest?

Tags:

angularjs

The AngularJS documentation for $http at http://docs.angularjs.org/api/ng.$http states "The $http service will not actually send the request until the next $digest() is executed.".

I was just wondering why it does not just make the HTTP request immediately? It seems like an unnecessary requirement, I wonder what I am missing.

UPDATE: Its been suggested that this is necessary because the completion handlers will need to update the digest. However, those completion events will need to make their own $apply/$digest call later either way.

like image 447
Frank Schwieterman Avatar asked Nov 11 '22 16:11

Frank Schwieterman


1 Answers

It's actually because $http is promise based. Full explanation here: https://github.com/angular/angular.js/issues/2794#issuecomment-18807158

like image 72
mmattax Avatar answered Nov 15 '22 12:11

mmattax