Angular - Convert a Observable to a number

前端 未结 2 738
傲寒
傲寒 2021-01-14 06:35

I\'m using ngrx store to record state, my state currently holds my list of accounts and the current page (for paging).

On my list of accounts component i call the st

相关标签:
2条回答
  • 2021-01-14 07:02

    You can create an async function and convert the observable to a promise and await it

    async method(){
        var pageNr = await this.currentPage$.toPromise();
        this.getListOfCustomer(pageNr);
    }
    
    0 讨论(0)
  • 2021-01-14 07:17

    subscribe to get result as number:

    let currentPageSub :Subscription;
    ...
    this.currentPageSub = this.store.select(getCurrentPage).subscribe(
     (page: number) => {
         this.currentPage$=page;
     }
    );
    
    0 讨论(0)
提交回复
热议问题