2

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
3
  • I do not understand your question. Please provide an example of input code , http response and expected result Commented Jun 15, 2015 at 12:21
  • Have you added url in whitelist ?stackoverflow.com/questions/29437035/… Commented Jun 15, 2015 at 13:10
  • more over : is it a get or a post/put that is executed ? for a simple get (read) it should generate terrible dammages Commented Jun 15, 2015 at 13:14

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.