Angular - Convert a Observable<number> to a number

孤人 提交于 2019-12-01 10:35:37

subscribe to get result as number:

currentPageSub :Subscription;
...
this.currentPageSub = this.store.select(getCurrentPage).subscribe(
 (page: number) => {
     this.currentPage$=page;
 }
);

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!