代码之家  ›  专栏  ›  技术社区  ›  user2859298

角度-将可观察的<数字>转换为数字

  •  4
  • user2859298  · 技术社区  · 8 年前

    我正在使用ngrx存储记录状态,我的状态当前包含我的帐户列表和当前页面(用于分页)。

    this.currentPage$ = this.store.select(getCurrentPage);
    

    getListOfCustomer(currentPage: number): Observable<ListDto<CustomerList>> {}
    

    我的变量 this.currentPage$ 当前是一种 Observable<number>

    可观察<数量> 到a number 把它传给我?

    2 回复  |  直到 8 年前
        1
  •  9
  •   Fateh Mohamed    6 年前

    let currentPageSub :Subscription;
    ...
    this.currentPageSub = this.store.select(getCurrentPage).subscribe(
     (page: number) => {
         this.currentPage$=page;
     }
    );
    
        2
  •  -1
  •   Titian Cernicova-Dragomir    8 年前

    您可以创建一个异步函数,并将可观察值转换为承诺,然后等待它

    async method(){
        var pageNr = await this.currentPage$.toPromise();
        this.getListOfCustomer(pageNr);
    }