这是我的类ts代码
this.product$ = <BehaviorSubject<Product>>this.route.params.switchMap(
(params): BehaviorSubject<Product> =>
this.productService.getProduct(params['_id'])
);这是来自服务的代码
getProduct(_id: string): BehaviorSubject<Product> {
const bs = new BehaviorSubject<Product>
(ProductService.initializeProduct());
if (_id !== '0') {
this.productSub = this.databaseService.getProduct(_id).subscribe(
product => {
bs.next(product);
}
);
}
return bs;
}我声明了type,还强制转换了type,但是当我编写
console.log(product$.getValue)我得到了这个错误:
错误TypeError: this.product$.getValue不是函数
谢谢
发布于 2017-07-14 13:07:17
一般来说,这不是switchMap和RxJS的工作方式。运算符返回的可观测值取决于调用该运算符的可观测值。所述可观察对象可以实现lift以返回相同类型的可观察实例。
您调用switchMap的结果将从this.route.params observable中删除。它不是BehaviorSubject,也没有getValue方法。
https://stackoverflow.com/questions/45094924
复制相似问题