【发布时间】:2019-02-10 23:53:07
【问题描述】:
我正在Angular 6 中创建搜索。我在直播时遇到了困难。
我希望我的 rx 流:
- 接受文本输入更改
- 与
subject结合使用,告诉流在单击按钮时获得更多结果(增量限制) - 调用服务
我有什么作品,除了:
- 当主题发出时,它什么也不做,我希望
switchmap启动并因此获得服务器响应.. -
如何在每次
subject发出 10 时增加限制?searchInput: FormControl = new FormControl(); showMore$: Subject<number> = new Subject(); ngOnInit() { this.searchInput .valueChanges .pipe( debounceTime(300), distinctUntilChanged(), withLatestFrom(this.showMore$.pipe(startWith(10), tap(val => { //how to increment the value here? }))), //switchmap not called when showMore$ emits... switchMap(([searchTerm, limit]) => { return this.myservice.search(searchTerm, limit) }), ) .subscribe(response => { this.results = response; }); } showMore(): void { this.showMore$.next(10); }
【问题讨论】: