[英]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.