在角度等待异步操作

时间:2018-04-27 07:09:51

标签: angular jhipster

在下面的代码片段中,我如何等待异步操作完成然后执行循环?

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;
        }
    }


}

1 个答案:

答案 0 :(得分:1)

更改Observable的承诺,或承诺的Observable,解决所有问题,然后运行循环。

a1=b0
b1 = a1 + b0