我希望仅在功能this.refresh()
完成后才能启动功能this.getAuthorizedDatabases()
。
您对如何轻松做到这一点有任何想法吗?
谢谢。
ngOnInit() {
this.userService.currentUser
.subscribe(res => {
this.user = res;
this.getAuthorizedDatabases();
});
this.refresh();
}
答案 0 :(得分:0)
除非getAuthorizedDatabases()
也可以异步进行
ngOnInit() {
this.userService.currentUser
.subscribe(res => {
this.user = res;
this.getAuthorizedDatabases();
this.refresh();
});
Observable是异步的,执行不会等待Observable完成。
答案 1 :(得分:0)
如果getAuthorizedDatabases()
是同步的。
ngOnInit() {
this.userService.currentUser
.subscribe(res => {
this.user = res;
this.getAuthorizedDatabases();
this.refresh();
});
}
如果getAuthorizedDatabases()
是异步的。使用Async-await
async ngOnInit() {
this.userService.currentUser
.subscribe(res => {
this.user = res;
await this.getAuthorizedDatabases();
this.refresh();
});
}