Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between $http and $q?

  • a) What are the difference between $http and $q ?
  • b) When should $q be implement over $http and vice versa ?
  • c) When and best practice for implement $http and $q at the same time?
like image 711
J Rod Avatar asked May 28 '15 16:05

J Rod


2 Answers

a) $http executes HTTP requests in an asynchronous manner, which means that you can not be sure about the time when you'll get an answer from the server. $q is a service that provides you the capability to execute multiple asynchronous tasks one after another. That being said they conceptionally do have nothing in common.

b) Consider a situation where you want to have multiple async HTTP calls to a server. You may have the possibility to nest each of those calls (for instance making the 2nd call in the success callback of the first call). However you find yourself in situations where you have various amounts of calls. You would then use $q to circumvent nesting code.

c) Whenever you have a single HTTP call you should use $http. Whenever you have numerous calls, you should use $q.

like image 111
Markus Avatar answered Sep 19 '22 10:09

Markus


a)

$http = angular service for access a server via the http protocol.

$q = angular service implementing kris kowalkis q library https://github.com/kriskowal/q. They are both angular service but have nothing else in common.

b)

$http uses $q to provide defered access (promises). But I know no situation where i would use $q over $http. As far as you want to make http requests.

c)

$http uses $q. So they are always used together. As long as you want to make http requests.

like image 41
Peter Paul Kiefer Avatar answered Sep 22 '22 10:09

Peter Paul Kiefer