From the course: Building Angular and ASP.NET Core Applications

Unlock the full course today

Join today to access over 24,500 courses taught by industry experts.

Reading data from Angular

Reading data from Angular

- Now that we have the HTML file ready, let us modify the DS file to read the data from the web API. For that we are going to first create a method in the Angular service. Then next we are going to inject this service in our component, then call the method from our component, and at the end, handle the response. Let's go to visual code and see this in action. In here, go to ClientApp, then source, app, and then services. In here open the book.service.ts file. Let us first define the base URL. And the base URL, which is of type string, is going to be api/books. For us to be able to send HTTP requests to our web API, we need to inject the HTTP client. So for that we write in here private http, and then httpClient. Now let us create a method to get all the books. For that, we just write in here getAllBooks, and then inside this method, we are going to return this.http. We want to send a get request, which is going to…

Contents