【发布时间】:2018-06-28 22:23:10
【问题描述】:
希望有人能对此有所了解
使用ngrx并尝试使用多个switchMaps来调用一些动作类。
我的行动:
export class BlogAddedAction implements Action {
readonly type = BLOG_ADDED_ACTION;
constructor(public payload:any) {
}
}
export class CrudSucessAction implements Action {
readonly type = CRUD_SUCCESS_ACTION;
constructor(public payload:any) {
}
}
export class BlogAddedToDBAction implements Action {
readonly type = BLOG_ADDED_TO_DB_ACTION;
constructor(public payload:any) {
}
}
effects.ts:
@Effect() addBlog$: Observable<any> = this.actions$
.ofType<BlogAddedAction>(BLOG_ADDED_ACTION)
.switchMap(action => {
console.log(action)
return this.blogService.addBlog(action.payload.blog)
})
.switchMap((action)=>new BlogAddedToDBAction(action))
.map((action)=>new CrudSucessAction(action))
}
但我收到 Typescript 错误:
[ts]
Argument of type '(action: Blog) => BlogAddedToDBAction' is not
assignable to parameter of type '(value: Blog, index: number) => ObservableInput<{}>'.Type 'BlogAddedToDBAction' is not assignable to type 'ObservableInput<{}>'.
Type 'BlogAddedToDBAction' is not assignable to type 'ArrayLike<{}>'.Property 'length' is missing in type 'BlogAddedToDBAction'.
尝试使用 map 而不是第二个 switchMap,但 BlogAddedToDBAction 没有被执行。
【问题讨论】:
标签: angular typescript rxjs ngrx