import { Component } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; @Component({ selector: 'app-root', template: `
import { Component } from '@angular/core'; import { Http, Headers } from '@angular/http'; @Component({ selector: 'app-root', template: ``, }) export class AppComponent { name: string; email: string; constructor(private http: Http) {} onSubmit() { const headers = new Headers({ 'Content-Type': 'application/json' }); const body = { name: this.name, email: this.email }; this.http.post('https://jsonplaceholder.typicode.com/users', body, { headers }) .subscribe(data => console.log(data)); } } In this example, the Http header is used to make an HTTP POST request to the JSONPlaceholder API and submit a new user to the server. The name and email values are taken from a form input using two-way data binding with Angular's [(ngModel)] directive. The headers object is used to specify the content type of the request as JSON, and the body object is passed as the payload.