取消ngFormControl事件触发

时间:2016-05-22 13:02:29

标签: angular

我有一个搜索字段的ngFormControl,我订阅了如下:

this.searchTerm.valueChanges
  .debounceTime(400)
  .distinctUntilChanged()
  .switchMap(searchTerm => this.locationSearchService.search(searchTerm))
  .subscribe(items => { doSomethingPartiallyInteresting() })

在某些情况下,我想取消.valueChanges事件触发。有谁知道这是不可能的吗?

1 个答案:

答案 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() })