1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
要在效果中進(jìn)行切換,您需要 2 個(gè)操作(開始和停止)并使用takeUntil.
//effects.ts
loadCourierItems$ = createEffect(() =>
this.actions$.pipe(
ofType(actions.start),
exhaustMap(action => interval(1000).pipe(
// logic for every second activity.
map(actions.everySecondAction()),
)),
takeUntil(this.actions$.pipe(ofType(actions.stop))),
repeat(),
)
)
//app.component.ts
constructor(private store: Store<CourierItemsState>) {
}
ngOnInit() {
this.store.dispatch(startAction());
}
ngOnDestroy() {
this.store.dispatch(stopAction());
}
添加回答
舉報(bào)