等待/停止代码执行,直到从服务器获取数据
wait/ stop in code execution until data getting from server
组件 1 在订阅中调用时有方法 A,我需要数组列表来检查一些条件,这些条件只能从组件 2 中的方法 Z 获得。数据将从数据库中获取,因此我需要等待方法-A 条件调用,直到获取数组列表。
这里checkArrayList()是检查arraylist获取数据的方法。
this.shareDataService.isLoading 标志在 method-z 调用中是 true/false。当从数据库 this.shareDataService.arrayList 加载数据时将更新。
let checkArrayList = async isLoad => {
do {
isLoad = this.shareDataService.isLoading;// true/false in method-z
if (isLoad) {
await new Promise(r => setTimeout(r, 500))
} else {
console.log(this.shareDataService.arrayList); // data will get here
}
}
while (isLoad) //when isload false while loop will break.
}
checkArrayList(this.shareDataService.isLoading); // calling function in method-A
组件 1 在订阅中调用时有方法 A,我需要数组列表来检查一些条件,这些条件只能从组件 2 中的方法 Z 获得。数据将从数据库中获取,因此我需要等待方法-A 条件调用,直到获取数组列表。
这里checkArrayList()是检查arraylist获取数据的方法。 this.shareDataService.isLoading 标志在 method-z 调用中是 true/false。当从数据库 this.shareDataService.arrayList 加载数据时将更新。
let checkArrayList = async isLoad => {
do {
isLoad = this.shareDataService.isLoading;// true/false in method-z
if (isLoad) {
await new Promise(r => setTimeout(r, 500))
} else {
console.log(this.shareDataService.arrayList); // data will get here
}
}
while (isLoad) //when isload false while loop will break.
}
checkArrayList(this.shareDataService.isLoading); // calling function in method-A