Issue
In Anguler js if I used two times $http in a single function so, will it affect the fetching of data from web services?
Like :-
.factory('Chats', function($http) {
$http{}
$http{}
});
Thanks
Solution
Fetching data using two $http calls is not a problem and they will not interfere with each other because they are called asynchronously.
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). 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. You can read more about this here: https://www.jonathanfielding.com/combining-promises-angular/
Answered By - JimTheDev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.