how can I send form data using post API using angular , have used form and method for component.ts file ,
<form #hlForm="ngForm" (ngSubmit)="getHospitalList(hlForm)">
<input
type="text"
class="input-texts"
name="name"
placeholder="Enter Hospital , Insurance or Location"
ngModel
required
>
<button
type="submit"
value="submit"
class="hl-btn"
(click)="hospitalFirstFold = false; hospitalSecondFold = true;"
>Search
</button>
</form>
getHospitalList(form){
console.log(form.value)
}
you need to create form data to send data using post api.
let fd = new FormData();
fd.append(key, value);
For api call
this.http.post(url, fd);
Fill values accordingly in formdata
Start by importing the necessary APIs:
import { HttpClient } from '@angular/common/http';
Declare submit function like below:
getHospitalList(form){
const formData = new FormData();
formData.append('key', form.value);
this.httpClient.post<any>(this.SERVER_URL, formData).subscribe(
(res) => console.log(res),
(err) => console.log(err)
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With