send form data post angular code example
Example 1: angular post form data to api
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
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;
});
}
Example 2: send data from form to another page angular
this.router.navigate('/results', { state: result });