【问题标题】:Angular6 Property 'debounceTime' does not exist on type 'Observable<any>'?'Observable<any>'类型上不存在Angular6属性'debounceTime'?
【发布时间】:2019-01-25 19:08:36
【问题描述】:

Angular update guide 之后将我的 Angular 5 项目更新为 Angular 6 后,我得到了。

Property 'debounceTime' does not exist on type 'Observable<any>'

在运行ng update 之后,我的所有组件都丢失了debounceTime import。但是我手动放回去了,但这并没有解决问题。

example.component.ts

import { debounceTime } from 'rxjs/operators';
 //Added after removed by ng update

 this.searchField.valueChanges
  .debounceTime(800)
  .distinctUntilChanged()
  .subscribe(term => {
    this.searchText = term;
    this.getAllDoctors();
  },

我真的很想了解这里发生了什么。

【问题讨论】:

  • angular.io/guide/rx-library#operators。您错过了“使用 rxjs-tslint 自动更新规则删除已弃用的 RxJS 6 功能”步骤。如果您正在执行此步骤,并且不使用仍使用旧 RxJS 语法的旧库,则不需要 rxjs-compat。
  • 然后阅读我链接到的文档,并描述应用运算符的语法。

标签: angular rxjs


【解决方案1】:

你需要使用管道运算符。

this.searchField.valueChanges
  .pipe(debounceTime(800),
        distinctUntilChanged()
   )
  .subscribe(term => {
    this.searchText = term;
    this.getAllDoctors();
  }),

【讨论】:

  • @DayOne 这个 wanswer 中的代码是正确的。如果它对您不起作用,请在您的问题中发布您尝试过的实际代码,并准确说明 如何 它不起作用。您预计会发生什么,以及会发生什么,准确地说。
猜你喜欢
  • 2017-10-20
  • 2016-09-01
  • 2017-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-26
  • 2018-11-16
  • 2020-11-01
相关资源
最近更新 更多