在下面的代码片段中,我如何等待异步操作完成然后执行循环?
ngOnInit() {
this.userService.query()
.subscribe((res: HttpResponse<User[]>) => { this.users = res.body; }, (res: HttpErrorResponse) => this.onError(res.message));
this.principal.identity().then((account) => {
this.currentAccount = account;
});
//my loop
for ( const user of this.users){
if (user.login === this.currentAccount.login){
this.currentUserId = user.id;
}
}
}
答案 0 :(得分:1)
更改Observable的承诺,或承诺的Observable,解决所有问题,然后运行循环。
a1=b0
b1 = a1 + b0