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.
Angular 6 onwards, debounceTime is imported as following. import { debounceTime } from 'rxjs/operators'; It is used with pipe operator of Observable . debounceTime is useful in operation where user changes inputs frequently such as search operation.
DebounceTime & Debounce are the Angular RxJs Operators. Both emit values from the source observable, only after a certain amount of time has elapsed since the last value. Both emit only the latest value and discard any intermediate values.
debounceTime delays the values emitted by a source for the given due time. If within this time a new value arrives, the previous pending value is dropped and the timer is reset. In this way debounceTime keeps track of most recent value and emits that most recent value when the given due time is passed.
I solved it with the help of @Siva636 and @Andrew Lobban.
I needed to use pipe:
this.field$.pipe(
debounceTime(400),
distinctUntilChanged())
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With