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

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Getting a single book from Angular

Getting a single book from Angular

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

Start my 1-month free trial

Getting a single book from Angular

- [Instructor] Now that we have created the book details view, it's time to get the data from the Web API. For that, we are going to create a method in our service. Then we are going to inject this service in our component. And at the end, we are going to handle result. So, let's see this in action. In here, go to ClientApp, src, app, services, and then book.service.ts file. Here we are going to create a method which takes the parameter of book ID and then returns a book. So let's write in here, "getBookById, id, it's of type number. We are going to return this.http.get which is going to return a Book response, then this._baseURL. And then in here we write inside double quotes, /singleBook, then /, and we append in here the id. Let us save the changes and go to our component. So inside the components folder, go to show-book, then show-book.component.cs. Let us inject in here the service so we can use the method…

Contents