繁体   English   中英

使用rxjs计时器和Observable替代http服务器

[英]Using rxjs timer and observable to substitute http server

我的搜索输入具有可观察性,我想使用计时器或setTimeout而不是使用服务器对其进行测试。

this.definitions = this.searchInput.valueChanges
                        .pipe(
                          startWith(''),
                          debounceTime(500),
                          distinctUntilChanged(),
                          switchMap(value => this.definitionService.searchTerm(value))
                        )

如何在搜索服务中返回带有计时的next()值的observable来测试输入订阅? 我想在x秒内生成响应。

searchTerm(term: string): Observable<Array<any>>
const searchTerm = (term: string): Observable<Array<any>> =>
  Rx.interval(1e3).pipe(map(() => generateFakeResult(term))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM