@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}
))
});
上面的代码给出了类型&#39;(有效载荷:任何)=&gt;的参数。空隙&#39;不能分配给&#39;类型的参数(值:any,index:number)=&gt; ObservableInput&#39 ;. 键入&#39; void&#39;不能分配给&#39; ObservableInput&#39;。 哪里可能是错误的。我在https://github.com/ngrx/effects/blob/master/docs/intro.md跟踪了ngrx特效官方介绍。
答案 0 :(得分:4)
问题是你的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}
))
});