角度-转换一个Observable< number>到一个数字 [英] Angular - Convert a Observable<number> to a number
问题描述
我正在使用ngrx存储来记录状态,我的状态当前包含我的帐户列表和当前页面(用于分页).
I'm using ngrx store to record state, my state currently holds my list of accounts and the current page (for paging).
在我的帐户列表组件中,我调用商店以获取当前页面,并将其传递给服务(Web API)以获取帐户列表.
On my list of accounts component i call the store to get the current page and pass that to a service (web api) to get the list of accounts.
this.currentPage$ = this.store.select(getCurrentPage);
我的角度服务期望一个变量(currentPage),但是作为一种数字类型,商店选择返回一个Observable.
My angular service is expecting a variable (currentPage) but as a type of number, the store select returns an Observable.
getListOfCustomer(currentPage: number): Observable<ListDto<CustomerList>> {}
我的变量this.currentPage$
当前是Observable<number>
我该如何转换
Observable<number>
传递到number
以将其传递给我的服务?
How can i convert an
Observable<number>
to a number
to pass it to my service?
推荐答案
订阅以数字形式获取结果:
subscribe to get result as number:
let currentPageSub :Subscription;
...
this.currentPageSub = this.store.select(getCurrentPage).subscribe(
(page: number) => {
this.currentPage$=page;
}
);
这篇关于角度-转换一个Observable< number>到一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!