Very useful post. Thank you.
Today the url works properly with https only and createPost method seems to be fine this way:
createPost(input: HTMLInputElement) {
input.value = "";
this.http.post(this.url, post)
.subscribe(response => {
post['id'] = response?.['id'];
this.posts.splice(0, 0, post);
});
}
After error handling:
createPost(input: HTMLInputElement) {
let post: any = { title: input.value };
input.value = '';
this.service.createPost(post)
.subscribe({
next: (response) => {
post['id'] = response?.['id'];
this.posts.splice(0, 0, post);
},
error: (error: Response) => {
if (error.status === 400) {
//this.form.setErrors(error);
}
else {
alert('An unexpected error occured.');
console.log(error);
}
}
});
}
Actually this post is pretty useful about the error handling section: