Angular 6 upgrade: debounceTime is not property of Subject

旧时模样 提交于 2019-12-05 15:30:21

问题


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.

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.


回答1:


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

I needed to use pipe:

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



回答2:


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

import {debounceTime} from 'rxjs/operators';

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

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.




回答3:


Following the reactivex docs, you should also subscribe to the pipe 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.




回答4:


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!



来源:https://stackoverflow.com/questions/50191318/angular-6-upgrade-debouncetime-is-not-property-of-subject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!