我在Angular 6
中创建了一个搜索。我有一个艰难的时间与我的流。
我希望我的rx流:
subject
的文本输入,该Call告诉流在单击按钮时获得更多结果(增量限制),并调用
服务
我所拥有的一切都是有效的,除了:
当主体发出时,它什么也不做,我希望switchmap
会介入,从而得到服务器response..
subject
发出时,我可以将限制增加10吗?searchInput: FormControl =新主题();showMore$:FormControl=新主题();ngOnInit() { this.searchInput .valueChanges .pipe( debounceTime(300),distinctUntilChanged(),withLatestFrom(this.showMore$.pipe(startWith(10),tap(val => {//如何在此处增加值?}),// showMore$发出...switchMap((searchTerm,limit) => { return this.myservice.search(searchTerm,limit) }),) .subscribe(response => { this.results = response;});} showMore():void { this.showMore$.next(10);}
发布于 2018-09-06 03:18:29
据我所知,switchMap应该可以按原样工作,尽管您可能希望在其中添加一些错误处理。
要将该值增加10,只需将该值放入存储中并触发一个操作,该操作将触发减法器在下一次循环中将其增加10。
.pipe(
debounceTime(300),
distinctUntilChanged(),
// get the value from the store using an ngrx selector
withLatestFrom(this.store.pipe(select(selectValue))),
switchMap(([searchTerm, limit]) => {
// essential to catchError else an HTTP error response will disable this
return this.myservice.search(searchTerm, limit).pipe(
catchError(() => {
return of('an error string which will be passed down the pipe on an error')
})
)
}),
tap(() => this.store.dispatch(new IncrementValueByTenAction()))
)
此外,在值沿管道向下传递时,使用大量的tap语句来记录值。
https://stackoverflow.com/questions/52191839
复制相似问题