I have a list of posts in my component that I retreive by using this code:
export class PostsComponent implements OnInit
{
posts;
constructor(private http: Http) { }
ngOnInit: void()
{
this.http.get('/posts').map(res => res.json()).subscribe(res => this.posts = res);
}
delete(post)
{
this.http.post('/posts/delete'+ post.id)
.subscribe(res =>
{
// delete post from posts, but how?
});
}
}
Now my question is how do I remove the post object from the array? Example of the array:
[
{
id: 1,
title: 'Test'
},
{
id: 2,
title: 'Test'
},
{
id: 3,
title: 'Test'
},
]
So I want to remove the post with id 2 from the array, so angular can update my display table. How would I do this?