Angular 9 中代码的执行顺序应该是什么?
What should be sequence of execution of the code in Angular9?
我有一个问题。 Angular9中有一个函数的代码,不知为何没有执行到行
this.selected.forEach(element => {
this.entryClient.update(<UpdateEntryCommand>{
id: element.id,
accepted: this.newEntryEditor.accepted,
rejected: this.newEntryEditor.rejected,
errorId: this.newEntryEditor.errorId
}).subscribe(() => {
counter++;
console.log(element.id);
}, error => {
console.log(error.reponse);
});
});
console.log(counter);
出于某种原因,首先执行 console.log(计数器),然后转到 this.selected...
有人可以解释一下为什么吗?
此致,
this.entryClient.update returns rxjs Observable 所以它是异步的。
this.selected.forEach 创建所有这些 Promise,然后在第一个 this.entryClient.update 完成之前执行 console.log(计数器)。
我有一个问题。 Angular9中有一个函数的代码,不知为何没有执行到行
this.selected.forEach(element => {
this.entryClient.update(<UpdateEntryCommand>{
id: element.id,
accepted: this.newEntryEditor.accepted,
rejected: this.newEntryEditor.rejected,
errorId: this.newEntryEditor.errorId
}).subscribe(() => {
counter++;
console.log(element.id);
}, error => {
console.log(error.reponse);
});
});
console.log(counter);
出于某种原因,首先执行 console.log(计数器),然后转到 this.selected... 有人可以解释一下为什么吗?
此致,
this.entryClient.update returns rxjs Observable 所以它是异步的。
this.selected.forEach 创建所有这些 Promise,然后在第一个 this.entryClient.update 完成之前执行 console.log(计数器)。