Update Another approach in this SO
a FormControl exist even if there're no input, so you can use a [ngModel] (ngModelChange)
declare an empty array of booleans (*)
focus:boolean[]=[]
And use some like:
<form [formGroup]="myform">
<input style="text-align:right"
[ngModel]="focus[0]?myform.get('control').value:(+myform.get('control').value).toFixed(2)"
(ngModelChange)="myform.get('control').setValue($event)"
[ngModelOptions]="{standalone:true}"
(focus)="focus[0]=true" (blur)="focus[0]=false">
</form>
Update you can also "format the number" using the angular formatNumber function -the function that use pipe number-. Just create a function format
import {formatNumber} from '@angular/common'
format(number:number)
{
return formatNumber(number,'en-US','0.2-2')
}
And replace the [ngModel]
in the input by
[ngModel]="focus[1]?myform.get('control2').value:format(+myform.get('control2').value)"
See the stackblitz
(*)I imagine you has severals "inputs", so for one of then use focus[0]
, for another one focus[1]
...