Sanwar Ranwa
What is $q service, deferred and promises ?
By Sanwar Ranwa in Angular on Feb 03 2018
  • Roshni Gandhi
    Jan, 2020 20

    When we want to send multiple requests/functions parallely or asynchronously we can use $q services.
    for example
    $q.all(request1,request2).then(function (response) {result1 = response[0];result2 = response[1];})

    Promises are provided by $q service. Promise is a placeholder for the values we will get in return from the requests/ functions we have used in $q services.

    Deferred object is to expose the results from Promise. there are some methods we can use to resolve the promise values i.e. resolve() and reject(). If there is some error in the values of the Promise we can call reject() method.

    I hope this is helpful.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS