使用异步功能完成地图后执行操作

时间:2019-12-05 15:11:49

标签: angular rxjs6

从这个意义上说,我正在获得产品,如果该产品具有“ childProducts”,它将成为一系列产品。

然后,在map函数上,数组中的每个产品都有一个弹出模式。

在所有产品的地图制作完成后,我想采取一些措施。

如何实现?

    @Effect()
    selectProductPage$ = this.actions$.ofType<SelectProduct>(OrderActionTypes.SelectProduct).pipe(
      map(action => action.payload),
      switchMap((product) => {
        const allTests = [product, ...(product.product.childProducts || [])].map(cloneDeep);
        return from(allProducts);
      }),
      map((product: any) => {
        // pop up modal for each product
      })
    );

1 个答案:

答案 0 :(得分:-1)

您可以使用点击 rxjs运算符在“地图”完成后执行一些操作。

所以您的代码将变成

@Effect()
    selectProductPage$ = this.actions$.ofType<SelectProduct>OrderActionTypes.SelectProduct).pipe(
      map(action => action.payload),
      switchMap((product) => {
        const allTests = [product, ...(product.product.childProducts || [])].map(cloneDeep);
        return from(allProducts);
      }),
      map((product: any) => {
        // pop up modal for each product
      }),
      tap((result) => this.finishRequest(result)) // HERE IS THE CHANGE
    );