Answers for "angular post form data to api"

0

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;
    });
}
Posted by: Guest on May-27-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language