Both get and post method of Http and HttpClient return Observable and it can be converted into Promise using toPromise() method. Returns promise (only if promise.constructor == Promise ) Promise.resolve(thenable); Make a new promise from the thenable. The resulting code that’s created is easier to read and is often written the order the application will execute. The HTTP client service offers the following major features. Join the community of millions of developers who build compelling user interfaces with Angular. For example, we use the content-type header to indicate the media type of the resource like JSON, text, blob, etc. Promises are a far cleaner solution to writing asynchronous code than callbacks. The code given below works for Angular 4.3 and Angular 5 apps. The promise In this tutorial, we'll learn about JavaScript/ES7 async and await keywords and we'll see how you can use them to write better asynchronous code in your Angular 7/8 apps with an example using HttpClient for sending HTTP requests and RxJS Observables. It starts with the HttpClientModule , which is in @angular/common/http . A thenable is promise-like in as far as it has a then() method. Added in Angular 4.3, HttpClient introduces a simpler way to make HTTP calls and a whole bunch of new features. So, what’s the difference when they both are dealing with asynchronous data. In Angular, we can use either Promise or Observable for handling asynchronous data. Angular uses Rx.js Observables, and it uses out of the box when dealing with HTTP requests instead of Promises. Angular provides a simplified client HTTP API for Angular applications, the HttpClient service class in @angular/common/http. * onwards. Promise.resolve(obj); Make a promise that fulfills to obj . With the catch handler it also gives us a singl… Angular has given tremendous features with every release of it. Help Angular by taking a … The ability to request typed response objects . The async pipe returns an empty string until the data is finally available (i.e. Some of the dominating features include support for Model-View pattern, special subjects like Async subject, Behaviour subject in Angular… In both cases, we use the httpHeaders configuration option provided by angular HttpClient to add the headers. Note that HttpClient is the recommended way for communicating with remote APIs from Angular 5. In this section, you will learn the usage of Promise with Angular HttpClient service. ). So it can be easier to trace through code in your head. I would hope more angular engineers would do the step to promises and async/await.. Because I often see bugs of duplocate listen on a subscription or simply listen on a steam that is guarantied to have only one event because it is an http request, going in and out, that`s it. That's why in the previous example we had to specify toPromise() to convert the Observable to a Promise This new module replaces HttpModule (and thus no need for @angular/http anymore! Angular httpclient will always return an observable (RXjs) , promise is deprecated in new Angular versions, you need to subscribe to the observable. Angular is a platform for building mobile and desktop web applications. in this situation. Example of Angular async pipe We will demonstrate a simple async pipe with a promise. Share. HTTP Headers let the client and the server share the additional information about the HTTP request or response. for more info read documentation to read more about Observables check this if you are new to Rxjs check this. Promise & Angular HttpClient Service. Improve this answer. until the promise is resolved, in case of a promise).