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:

  1. Inject the LaptopService into the component CreateLaptopComponent constructor like this constructor(laptopService: LaptopService)

  2. Add this code in the sendLaptopToDatabase() in your component

    this.laptopService.sendLaptop(this.loginForm.value).subscribe(laptop => {console.log(laptop});
    

Instead of the console.log() you can handle the response as you want.