小编Man*_*rás的帖子

如何链接 Angular 可观察量?

我的组件需要在发出 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)

rxjs typescript angular

0
推荐指数
1
解决办法
8490
查看次数

标签 统计

angular ×1

rxjs ×1

typescript ×1