AngularJS:为什么$ HTTP,直到你离开当前摘要没有真正发挥http请求? [英] AngularJS: Why does $http not actually make a http request until you leave the current digest?

查看:81
本文介绍了AngularJS:为什么$ HTTP,直到你离开当前摘要没有真正发挥http请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularJS文档$ HTTP在 http://docs.angularjs.org/api/ng $ HTTP指出$ HTTP服务实际上不会发送请求,直到下一个$摘要()被执行。

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.".

我只是想知道为什么它不只是把HTTP请求立即?这似乎是不必要的要求,我不知道我错过了什么。

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.

推荐答案

这是因为$ HTTP是基于承诺实际上是。在这里充分的解释: https://github.com/angular/angular.js /问题/ 2794#issuecomment-18807158

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

这篇关于AngularJS:为什么$ HTTP,直到你离开当前摘要没有真正发挥http请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆