What is the difference between $http and $q?
Asked Answered
S

2

6
  • 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?
Selfness answered 28/5, 2015 at 16:17 Comment(2)
One is http library, the other - a promise library. $http uses $q underneath.Austere
(a) Nutshell: everything, (b) see (a)Musil
P
8

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.

Pemba answered 28/5, 2015 at 16:25 Comment(0)
R
1

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.

Rumen answered 28/5, 2015 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.