From the course: Building Angular and ASP.NET Web API Apps

Unlock the full course today

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

Creating an HttpPost request in Angular

Creating an HttpPost request in Angular

From the course: Building Angular and ASP.NET Web API Apps

Start my 1-month free trial

Creating an HttpPost request in Angular

- [Instructor] So on this part, we are going to connect these two to each other. So we are going to create a method. Then we are going to inject our service in our new component. And then we are going to send the data, so we are going to send the request. So let's get started. In our entry.service.ts file, let us create a new method named createEntry. And this method will take as a parameter an entry. Once we have the entry we want to send the post request to our back end. So for that we write return.this.http.post because we want to send a post request, and we already have the base urls. So for that we write in here this.baseUrl. And then we are going to send the entry as a parameter. So this is all you have to do in your service. Now let us go back to our component and inject this service. So inside the new entry folder, go to your new-entry.component.ts file. And inside the constructor, let us inject our service. For that, write private service and then Entry Service. To use this…

Contents