I have a reactive form with one field and when the user stops typing, I want to print to the console the value. For this purpose I use the debounceTime()
when the value in the field is changed.
I read several questions about the use of the debounceTime()
like How to use debounceTime in an angular component? and Angular and debounce but my code prints the latest value more than once then the change is detected and the time in the debounceTime function is elapsed.
The input filed of the form is this:
<input matInput formControlName="name" (keyup)="onInputChange()">
The code in function onInputChange is this:
this.userForm.get("name").valueChanges
.pipe(
debounceTime(500)
)
.subscribe(res => {
console.log(res)
});
It the input is test
the result in console is the following image:
What could be wrong?