等待/停止执行代码,直到从服务器获取数据[关闭]

问题描述 投票:-1回答:1

Component-1在订阅中获得调用时具有方法A,我需要数组列表来检查某些条件,这些条件仅从component-2中的方法Z获得。数据将从DB中获取,因此我需要等待Method-A条件调用,直到arraylist将获得。

problem explain in flow chart

javascript async-await angular7
1个回答
0
投票

这里,checkArrayList()是一种检查数组列表将获取数据的天气的方法。在method-z调用中this.shareDataService.isLoading标志为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

© www.soinside.com 2019 - 2024. All rights reserved.