简体   繁体   English

Ionic angularjs $http 模块未获取数据

[英]Ionic angularjs $http module is not get data

In anguler js if I used two times $http in single function so, will it affect the fetching data from web services.在anguler js中,如果我在单个函数中使用了两次$http,那么它是否会影响从Web服务中获取数据。

Like :-
.factory('Chats', function($http) {
  $http{}
  $http{}
});

Thanks

Fetching data using two $http calls is not a problem and they will not interfere with each other because they are called asynchronously.使用两个 $http 调用获取数据不是问题,它们不会相互干扰,因为它们是异步调用的。

This is great because it means that they will both be called nearly immediately without one having to wait for the other to complete.这很棒,因为这意味着它们几乎都会立即被调用,而无需等待另一个完成。

You should know, however, that because of this you could get the results of the second call before you get the results of the first call.但是,您应该知道,因此您可以在获得第一次调用的结果之前获得第二次调用的结果。 This might happen if you were to have a very long call (large amount of data) in your first $http and a very short one (small amount of data).如果您在第一个 $http 中有一个很长的调用(大量数据)和一个很短的调用(少量数据),则可能会发生这种情况。 If you want to wait for both to be completed before proceeding then you can use $q.all to wait for both to complete before proceeding.如果您想在继续之前等待两者都完成,那么您可以使用 $q.all 等待两者都完成后再继续。 You can read more about this here: https://www.jonathanfielding.com/combining-promises-angular/您可以在此处阅读更多相关信息: https : //www.jonathanfielding.com/combining-promises-angular/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM