1import { HttpClient } from '@angular/common/http';
2import { HttpClient, HttpHeaders } from '@angular/common/http';
3
4//http to your constructor
5constructor(private http: HttpClient) { }
6
7ngOnInit() {
8 let headers = new HttpHeaders({
9 'Content-Type': 'application/json'});
10 let options = { headers: headers };
11 const body = { title: 'Angular POST Request Example' };
12 this.http.post<any>('https://reqres.in/api/posts', body, options).subscribe(data => {
13 this.postId = data.id;
14 });
15}