`withLatestFrom`-使用可观察的实现抛出错误

时间:2019-05-08 10:20:11

标签: rxjs ngrx rxjs-pipeable-operators

我正在尝试使用ngrx rxjs运算符集成withLatestFrom缓存。但是出现错误:

You provided 'undefined' where a stream was expected.
You can provide an Observable, Promise, Array, or Iterable.

有人纠正我的密码吗?

这是我的代码:

@Effect()
EffLoadCourse = this.actions.pipe(
  ofType(LoadCourse.TYPE),
  withLatestFrom(
    this.store.pipe(select(subscribes.getCourses)), //getting it from store
    (action: LoadCourse, courses: ModelCourse[]) => {
      // console.log('action is ', action, 'courses is', courses)
      return courses;
    }
  ),
  mergeMap((courses: ModelCourse[]) => {

    if (courses) { //if courses available just return it
      map((courses: ModelCourse[]) => (new LoadCourseSuccess(courses))),
        catchError(err => of(new LoadCourseFail(err)))
      return;
    }
    //only return on courses unavailability
    return this.courseService.getCourse().pipe(
      map((courses: ModelCourse[]) => (new LoadCourseSuccess(courses))),
      catchError(err => of(new LoadCourseFail(err)))
    )
  })
)

1 个答案:

答案 0 :(得分:1)

   if(courses){ //if courses available just return it
                    map((courses:ModelCourse[]) => (new LoadCourseSuccess(courses))),
                    catchError(err => of(new LoadCourseFail(err)))
                    return;
                }

您没有返回任何动作,只是一个void