@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}
))
});
上面的代码给出了类型'(payload:any)=> void'的参数不能赋值给'(value:any,index:number)=> ObservableInput'类型的参数。类型'void'不能分配给'ObservableInput'类型。哪里可能是错误的。我跟随https://github.com/ngrx/effects/blob/master/docs/intro.md的ngrx特效官方介绍。
问题是你的switchMap应该返回一个值;你有它的回归空虚。
试试这个
@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);
return this.searchService.getsearchresults(payload)
.takeUntil(nextSearch$)
.map((response) =>
({type: '[Search] Change', payload: response}
))
});