The bulk of this chapter has focused on how the Angular HTTPClient
uses Observables as the default for XMLHttpRequests
. This represents a significant change from the way things used to work. Many developers are familiar with using promises for asynchronous HTTP requests. With that being the case, Angular continues to support promises, but just not as the default choice. A developer has to opt for promises in an XMLHttpRequest
in order to be able to use them.
For example, if we want to use promises with the getExercises
method in WorkoutService
, we will have to restructure the command as follows:
getExercises(): Promise<Exercise[]> { return this.http.get<Exercise[]>(this.collectionsUrl + '/exercises' + this.params) .toPromise() .then(res => res) .catch(err => { return Promise.reject(this.handleError('getExercises', [])); }); }
In order to convert this method to use promises, all we...