tap() isn't triggered in RXJS Pipe

后端 未结 2 1222
灰色年华
灰色年华 2020-12-11 15:10

I have to ways of doing the same thing, although I prefer the first one. But the first approach doesn\'t seem to work. (the tap() is not triggered)



        
2条回答
  •  有刺的猬
    2020-12-11 16:04

    pipe creates new Observable thus you must asssign it and then subscribe to that isntance. In your case you are ommiting pipe return thus you end up with plain, unmodified Observable without any extra pipe actions.

    Also remember that most likely you will have to subscripbe in order to pipe (and tap) to work.

    try

    this.actions$=this.actions$.pipe(
        tap(()=>console.log("First tap")),
        ofType(LayoutActions.Types.CHANGE_THEME),
        takeUntil(this.destroyed$),
        tap(() => {
            console.log('Last tap')
        }),
    );
    
    this.actions$.subscribe(() => {
        console.log('subscribtion')
    });
    

提交回复
热议问题