
I want to start with this because it nicely describes the common usage pattern for creating custom Promises in JavaScript. Let’s start with the more complex verbose way of creating an extra promise which seems to be a commonly used pattern I’ve seen in a number of examples (including a number of online training courses). You then implement a service to get the data via $http and a controller that can use the data that the service provides. Assume you have a small HTML block with an ng-repeat that displays some data: Let’s look at a simple example (also on Plunker).

Let’s look at a few different approaches to help us understand how the $http service works with its custom promises. The idea is simple enough – you want to create a service that captures the data and stores is and then notify the controller that the data has changed or refreshed.
#CROSSCODE A PROMISE IS A PROMISE 1 LOCATION CODE#
This might explain that when looking at samples of Angular code that use the $http service inside of custom services, I often see code that creates a new wrapper Promise and returns that back to the caller rather than the original $http Promise. Underneath the $http callbacks there is still a $q Promise, but the extension functions abstract away some of the ugliness that is internal to the $http service. The various $http.XXXX functions however, typically use the.

then() receives parameters for a success and failure callback. then() function to provide a continuation on success or failure, and. Traditional promises (using the $q Service in Angular) have a. rather than relying on the more standard. When using the $http service with Angular I’ve often wondered why the $http service opts to use a custom Promise instance that has extension methods for.
