我对RxJsandNgRx store很陌生,我想创建一个@Effectwith 两个 observables 的组合(很难解释):
我的界面看起来像:
export interface ProductDetails {
product: Product;
productBody: ProductBody;
}
export interface ProductBody{
id: string;
body: string;
}
我正在尝试创建一个新对象productDetails并设置它的属性。属性是productwhich payloadhasproduct和productBodywhich get from productService(id)(It returns observable<productBody>)
这个效果应该返回observable<productDetails>
@Effect()
getProductDetails$ = this.actions$
.ofType(ProductActions.GET_STEP)
.map(action => action.payload)
.flatMap(s => {
let body;
this.productService.getStepBody(s.id).subscribe(x => body = x);
return Observable.of({
step: s,
productBody: body
});
})
.map(res => this.productActions.getProductDetailsSuccess(res));
这返回:Object {productBody: undefined, product: Object}
我明白为什么要返回undefined但productBody不知道如何解决它。我尝试使用zip,switchMap等但没有机会!