typescript Angular 6 升级:debounceTime 不是主题的属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50191318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:23:16  来源:igfitidea点击:

Angular 6 upgrade: debounceTime is not property of Subject

angulartypescriptrxjs

提问by Logan_B

I am attempting to upgrade my app from Angular 5 to Angular 6. I followed the steps on the https://update.angular.io/At least i think i did.

我正在尝试将我的应用程序从 Angular 5 升级到 Angular 6。我按照https://update.angular.io/上的步骤操作 至少我认为我做到了。

The Error is :

错误是:

Property 'debounceTime' does not exist on type 'Subject<string>'.

Also my components lost the debounceTime import. I think the ng update removed it.

我的组件也丢失了 debounceTime 导入。我认为 ng 更新删除了它。

回答by Logan_B

I solved it with the help of @Siva636 and @Andrew Lobban.

我在@Siva636 和@Andrew Lobban 的帮助下解决了这个问题。

I needed to use pipe:

我需要使用管道:

  this.field$.pipe(
      debounceTime(400),
      distinctUntilChanged())

回答by Heena Manglani

As of Angular 6.1.8, just need to import and add pipe like below example

从 Angular 6.1.8 开始,只需要像下面的例子一样导入和添加管道

import {debounceTime} from 'rxjs/operators';

Then on field just before the observable subscribe method call pipe(debounceTime(1000)) like below:

然后在可观察订阅方法调用 pipe(debounceTime(1000)) 之前的字段上,如下所示:

emailControl.valueChanges.pipe(debounceTime(1000)).subscribe(value => this.setMessage(emailControl));

And that's it, it's just a updated answers of @tiago's answer - where she is defining const debouncetime - we don't really need to use const and pipe.

就是这样,这只是@tiago 答案的更新答案——她在其中定义了 const debouncetime——我们真的不需要使用 const 和管道。

回答by jmuhire

Following the reactivex docs, you should also subscribe to the pipe observable :

遵循reactivex docs,您还应该订阅管道observable:

.pipe(
    debounceTime(500),
    distinctUntilChanged(),
    map((val) => {
        ...
    })
)
.subscribe();

An Observable is called a “cold” Observable if it does not begin to emit items until an observer has subscribed to it.

如果 Observable 直到观察者订阅它才开始发出项目,则它被称为“冷” Observable。

回答by Tiago Neiva

i am sorry for the delay but i just get this problem today and fixed like this. i solve this issue like this: first import like this:

我很抱歉延迟,但我今天刚遇到这个问题并像这样修复。我是这样解决这个问题的:首先像这样导入:

import {debounceTime} from 'rxjs/operators';
import {pipe} from 'rxjs'

Then create a const like this (i tried to do directly without duplicating pipe but didn′t work so i found this solution):

然后创建一个像这样的常量(我试图直接做而不复制管道但没有用所以我找到了这个解决方案):

const debouncetime = pipe(debounceTime(1000));

And then use it before you subscribe for example i was doing an email validator with messages:

然后在订阅之前使用它,例如我正在做一个带有消息的电子邮件验证器:

const emailControl = this.registerForm.get('email');
    emailControl.valueChanges
     .pipe(debouncetime)
     .subscribe(value => this.setEmailMessage(emailControl))

dont know if its the best solutions but it works perfectly. I hope it helps some one!

不知道它是否是最好的解决方案,但它完美无缺。我希望它可以帮助某人!