Vij*_*esh 4 javascript rxjs typescript ngrx angular
ngrx 效果在返回值后被多次调用。
loadMovies$: Observable<Action> = createEffect(() => {
return this.actions$.pipe(
ofType(counterActions.CounterActionTypes.IncrementCounter),
flatMap(() => {
return this.userService.counter()
.pipe(
map(movies => {
return new counterActions.IncrementCounter();
}));
}
));
});
Run Code Online (Sandbox Code Playgroud)
你应该添加dispatch: false
你的效果
loadMovies$ = createEffect(() => {
this.actions$.pipe(
ofType(counterActions.CounterActionTypes.IncrementCounter),
flatMap(() => {
return this.userService.counter()
.pipe(
map(movies => {
return new counterActions.IncrementCounter();
}));
}
)),
{ dispatch: false };
});
Run Code Online (Sandbox Code Playgroud)
文档中的示例
logActions$ = createEffect(() =>
this.actions$.pipe(
tap(action => console.log(action))
), { dispatch: false });
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4735 次 |
最近记录: |