angular post form data to api
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
//http to your constructor
constructor(private http: HttpClient) { }
ngOnInit() {
let headers = new HttpHeaders({
'Content-Type': 'application/json'});
let options = { headers: headers };
const body = { title: 'Angular POST Request Example' };
this.http.post<any>('https://reqres.in/api/posts', body, options).subscribe(data => {
this.postId = data.id;
});
}