- 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?
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
.
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.
© 2022 - 2024 — McMap. All rights reserved.
$http
uses$q
underneath. – Austere