我无法在效果文件中发送动作。当我返回数据而不是 loadFilesSuccess() 时它会起作用。
import { Injectable } from "@angular/core";
import { Actions, createEffect, ofType} from "@ngrx/effects";
import { RequestService } from "../services/request.service";
import { loadFiles,loadFilesSuccess, increment } from "../actions/files.actions";
import { mergeMap, map, catchError, exhaustMap } from "rxjs/operators";
import * as FilesActions from '../actions/files.actions';
@Injectable({
providedIn: "root"
})
export class RequestEffects {
constructor(private actions$: Actions, private requestService: RequestService) { }
sendFile$ = createEffect(() => {
return this.actions$.pipe(
ofType(loadFiles),
exhaustMap((action) => {
return this.requestService.sendDatas(action.data).pipe(
map((data: any) => {
console.log(data)
return loadFilesSuccess()
}),
catchError((error) => {
console.log(error)
return error
})
)
})
)
});
}
您可以在效果中调度一个动作,但不建议这样做。 有关更多信息,请参阅https://ngrx.io/guide/eslint-plugin/rules/no-dispatch-in-effects。