我有一个搜索字段的ngFormControl,我订阅了如下:
this.searchTerm.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.switchMap(searchTerm => this.locationSearchService.search(searchTerm))
.subscribe(items => { doSomethingPartiallyInteresting() })
在某些情况下,我想取消.valueChanges事件触发。有谁知道这是不可能的吗?
答案 0 :(得分:0)
也许您可以利用filter
运算符:
this.searchTerm.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.filter(() => { // <------------
return !(this.address === 'don't handle this address');
})
.switchMap(searchTerm => this.locationSearchService.search(searchTerm))
.subscribe(items => { doSomethingPartiallyInteresting() })