[英]How to await on a variable to change its value in Angular?
I have a variable which changes its value upon an HttpRequest is completed.我有一个变量,它会在 HttpRequest 完成时更改其值。 Its value is false
unless the HttpRequest is finished.除非 HttpRequest 完成,否则它的值为false
。 Is it possible to use it in a conditional statement?是否可以在条件语句中使用它? So far I have tried:到目前为止,我已经尝试过:
async getAsyncValue() {
const loading = await this.dataSource.loading$.toPromise();
if (!loading) {
// do something
}
}
this.dataSource.loading$.subscribe((data) => {
//do something
}
Assuming the loading$ is an observable.假设 loading$ 是一个可观察的。 You don't really need to convert it to a promise.你真的不需要把它转换成一个承诺。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.