Using angular 7
and rxjs 6
:
<input (input)="onChange($event.target.value)">
Why the following does not debounce?
onChange(val: string) {
of(val)
.pipe(
debounceTime(300)
).subscribe(valx => {
console.log(valx);
});
}
But this does:
searchTerm$: Subject<string> = new Subject();
this.searchTerm$.pipe(
debounceTime(300),
).subscribe(val => {
console.log(val);
});
onChange(val: string) {
this.searchTerm$.next(val);
}