Issue
Unlike other types of HTML inputs, I found it rather surprising that typing into an input of type Number would trigger valueChanges when the input is blurred, as well as clicking on the spinners (the small arrows on the side) would trigger valueChanges twice, is this an expected behavior, or am I missing something?
Component:
export class AppComponent {
textControl = new FormControl();
numberControl = new FormControl();
ngOnInit(): void {
this.textControl.valueChanges.subscribe(console.log)
this.numberControl.valueChanges.subscribe(console.log)
}
}
Template:
<input type="text" [formControl]="numberControl">
<input type="number" [formControl]="textControl">
Here's Stackblitz demo
Solution
This is a known issue which has been already fixed in Angular 10
Forked Stackblitz with Angular 10
Prior to this fix Angular listed to two events:
host: {
'(change)': 'onChange($event.target.value)',
'(input)': 'onChange($event.target.value)',
Starting from Angular 10 it listens only for one:
host: {
'(input)': 'onChange($event.target.value)'
Answered By - yurzui
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.