How to make a POST request with Angular HttpClient?
Solution 1:
You can simply call your API by doing a post request by following these steps:
-
Inject the
LaptopService
into the componentCreateLaptopComponent
constructor like thisconstructor(laptopService: LaptopService)
-
Add this code in the
sendLaptopToDatabase()
in your componentthis.laptopService.sendLaptop(this.loginForm.value).subscribe(laptop => {console.log(laptop});
Instead of the console.log() you can handle the response as you want.