post request in angular code example
Example 1: angular post request
ngOnInit() {
this.http.post<any>('https://reqres.in/invalid-url', { title: 'Angular POST Request Example' }).subscribe({
next: data => {
this.postId = data.id;
},
error: error => {
this.errorMessage = error.message;
console.error('There was an error!', error);
}
})
}
...
interface Article {
id: number;
title: string;
}
Example 2: angularjs make post request
var url = 'posturl', data = 'parameters',config='contenttype';
$http.post(url, data, config).then(function (response) {
// This function handles success
}, function (response) {
// this function handles error
});