I want to implement debouncing.
Vanilla java script code will look like this
onInputChange(ev) {
clearTimeout(this.timer);
this.timer = setTimeout(() => {
this.http.get('https://jsonplaceholder.typicode.com/users').subscribe(users => console.log('users', users));
},700)
}
but i can't find a way to do the same with rxjs in my angular compomonent
i tried
i found the debounceTime
operator but it still makes requests every time. There is no delay of 1000 miliseconds
this.http.get('https://jsonplaceholder.typicode.com/users')
.pipe(debounceTime(1000))
.subscribe(users => console.log('users', users));
Also i tried
<input [(ngModel)]="newUser" (input)="onInputChange($event)" [formControl]="newUserControll"/>
this.newUserControll.valueChanges.pipe(
debounceTime(1000)
switchMap(() => interval(1000))).subscribe(x => console.log('x', x))
but i get
',' expected.
error