Other options futhermore the comments
You can make something like this another SO. If you has a variable in .ts focus
focus:boolean=false;
You can write some like
<input matInput style="width:100%;" type="number"
[ngModel]="focus?inputTarget:(inputTarget | number : '1.2-2')"
(ngModelChange)="inputTarget = $event"
(blur)="focus=false"
(focus)="focus=true" autocomplete="off">
Or you can make a directive
@Directive({
selector: '[format]',
exportAs: 'child'
})
export class FormatDirective implements OnInit {
focus:boolean=false;
value:any;
@Input('format') formato:string
@HostListener('blur') _(){
this.focus=false;
this.value=this.control.control.value;
this.control.control.setValue(formatNumber(this.value,'en-US',this.formato))
}
@HostListener('focus') __(){
this.focus=true;
this.control.control.setValue(this.value)
}
constructor(private control:NgControl){}
ngOnInit(){
setTimeout(()=>{
this.value=this.control.control.value;
this.control.control.setValue(formatNumber(this.value,'en-US',this.formato))
})
}
}
The stackblitz
NOTE: If you "format" the number with thousand separators the type can not be "number"