我的组件需要在发出 API 请求之前检查是否设置了某些应用程序首选项。现在我已经这样设置了,我以 2 分钟的计时器更新组件的数据:
ngOnInit(): void {
this.subscription = timer(0, 120 * 1000).subscribe(() => {
this.shopService.getPreferencesAsObservable().subscribe(preferences => {
if(preferences) {
this.getInitialPendingSlotsOrders();
this.getInitialPendingNoSlotsOrders();
}
});
});
}
getInitialPendingSlotsOrders(){
this.apiService.fetchShopOrders("status=PENDING&only_slots=true").subscribe(orders=> {
/* do stuff with orders */
/* it can happen that I need to get another page of data */
if(orders.next_page){
this.getNextSlotsSetOfPendingOrders();
}
});
}
getInitialPendingNoSlotsOrders(){
this.apiService.fetchShopOrders("status=PENDING").subscribe(orders=> {
/* do stuff with orders */
/* it can happen that I need to get another page of data */
if(orders.next_page){
this.getNextNoSlotsSetOfPendingOrders(); …Run Code Online (Sandbox Code Playgroud)