Using the $q Service to Provide Deferred Responses

An extremely useful service provided by AngularJS is the $q service. The $q service is a promise/deferred response implementation. Since not all services can respond immediately to a request, there is a need to defer the response until the service is ready to respond. That is where the $q service comes in. The idea is that you can make a request, and rather than getting the response directly, you will get a promise that the service will respond. The requesting application can then assign a callback function that should be executed when the deferred request completes successfully or fails.

To utilize the $q service for deferred responses, you will first need to create a deferred object using ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.