【发布时间】:2018-07-12 00:23:06
【问题描述】:
我不确切知道 Angular 或 Typescript 是如何工作的,我认为在这段代码中,它应该是 3 1 2。但它是 1 2 3。请帮助我。
confirmDelete(id: number) {
this.commentService.queryByStoryId(id).subscribe(
(res: ResponseWrapper) => {
this.comments = res.json;
console.log(3);
},
(res: ResponseWrapper) => this.onError(res.json)
);
console.log(1);
console.log(2);
// for (let i = 0; i < this.comments.length; i++) {
// this.commentService.delete(this.comments[i].id);
// }
this.postService.delete(id).subscribe((response) => {
this.eventManager.broadcast({
name: 'postListModification',
content: 'Deleted an post'
});
this.activeModal.dismiss(true);
});
}
【问题讨论】:
-
javascript 不阻止
-
3 1 2 是正确的,因为 console.log(3) 将被处理。这意味着,这个 observable 需要被调用。我的情况是 1,2,然后是 eventManger.broadcast 或观察者呼叫的某个地方。在此处查看有关反应式编程的更多信息github.com/Reactive-Extensions/RxJS
-
@DaveClough:并不是说 JavaScript 不会阻塞;就是非阻塞的东西不会阻塞。
标签: angular typescript jhipster