1ngOnInit() {
2 this.http.post<any>('https://reqres.in/invalid-url', { title: 'Angular POST Request Example' }).subscribe({
3 next: data => {
4 this.postId = data.id;
5 },
6 error: error => {
7 this.errorMessage = error.message;
8 console.error('There was an error!', error);
9 }
10 })
11}
12
13...
14
15interface Article {
16 id: number;
17 title: string;
18}
1var url = 'posturl', data = 'parameters',config='contenttype';
2
3$http.post(url, data, config).then(function (response) {
4
5// This function handles success
6
7}, function (response) {
8
9// this function handles error
10
11});