Answer the question
In order to leave comments, you need to log in
How to properly make a subscribe inside another subscribe?
addPost() {
this.openDialog().subscribe(formData => {
if (formData) {
this.postsService.add(formData).subscribe((res: Post) => {
this.posts.unshift(res);
});
}
});
}
Answer the question
In order to leave comments, you need to log in
don't do that, use flatMap
this
.openDialog()
.flatMap(fd=>{
return !fd?Observable.Empty():this.postsService.add(fd).first();
})
.subscribe(post=>{
this.posts.unshift(post);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question