Go ProSign in

This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Create an Angular Service to Retrieve Data from an API

In this lesson we will create the ProductsService that is responsible for the interaction with our API.

We will inject the HttpClient that we get from @angular/common/http. To make this working we need to import HttpClientModule in our AppModule.

We define a getProducts and getProduct method so we can get a list of products and an single product which we will use in respectively the ProductList and ProductDetail components.

In both components we will use the ngOnInit lifecycle hook to invoke the methods on the service, and retrieve the data by subscribing to it.

You must be a Member to view code