这是我的特效文件,
import { Injectable } from "@angular/core";
import { Action } from "@ngrx/store";
import { Actions, Effect, ofType } from "@ngrx/effects";
import { Observable, of } from "rxjs";
import { map, mergeMap, switchMap, catchError } from "rxjs/operators";
import { ModelCourse } from "./../models";
import { CourseService } from "./../services/course.service";
import {
courseActionTypes,
LoadCourse,
LoadCourseSuccess,
LoadCourseFail,
UpdateCourse,
UpdateCourseSuccess,
UpdateCourseFail } from "./course.actions";
@Injectable()
export class CourseEffects {
constructor(private courseService:CourseService, private actions:Actions){}
@Effect()
LoadCourse = this.actions.pipe(
ofType(LoadCourse.TYPE),
mergeMap((action:LoadCourse) => this.courseService.getCourse().pipe(
map((courses:ModelCourse[]) => {
return new LoadCourseSuccess(courses);
}),
catchError(err => of(new LoadCourseFail(err)))
))
)
@Effect()
UpdateCourse = this.actions.pipe(
ofType(UpdateCourse.TYPE),
map((action:UpdateCourse) => action.payload),
mergeMap((course:ModelCourse) =>
this.courseService.updateCourse(course).pipe(
map((course) => (new UpdateCourseSuccess(course))),
catchError(err => (new UpdateCourseFail(err)))
)
)
)
}
从上面,我收到以下错误。有人帮我吗?
ERROR in src/app/setup-config/state/course.effects.ts(41,24): error TS2322: Type 'UpdateCourseFail' is not assignable to type 'ObservableInput<{}>'.
Property '[Symbol.iterator]' is missing in type 'UpdateCourseFail' but required in type 'Iterable<{}>'.
这是我的错字,我用of
运算符更新了catchError。它现在工作正常。
这是更新的代码:
catchError(err => of(new UpdateCourseFail(err)))
谢谢!!