van*_*ers 3 rxjs ngrx ngrx-effects angular ngrx-store
@Injectable()
export class ApiSearchEffects {
@Effect()
search$: Observable<any>
= this.actions$
.ofType(query.ActionTypes.QUERYSERVER)
.debounceTime(300)
.map((action: query.QueryServerAction) => action.payload)
.switchMap(payload => {
console.log(payload);
const nextSearch$ = this.actions$.ofType(query.ActionTypes.QUERYSERVER).skip(1);
this.searchService.getsearchresults(payload)
.takeUntil(nextSearch$)
.map((response) =>
({type: '[Search] Change', payload: response}
))
});
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我 '(payload: any) => void' 类型的参数不能分配给类型 '(value: any, index: number) => ObservableInput' 的参数。“void”类型不能分配给“ObservableInput”类型。哪里可能出错。我遵循了https://github.com/ngrx/effects/blob/master/docs/intro.md 上的 ngrx 效果官方介绍。
问题是你的 switchMap 应该返回一个值;当你拥有它时,它会返回无效。
尝试这个
return this.searchService.getsearchresults(payload)
.takeUntil(nextSearch$)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9254 次 |
| 最近记录: |