This is my input:
<input [(ngModel)]="minimumRange" min="1" placeholder="0.0" step="0.1" type="number">
What I need is, when someone enters
"1"
, I need it to return
"1.0".
on blur How is this possible?
Using the number @Pipe you should be able to achieve this.
<input [ngModel]="minimumRange | number : '1.1-2'" min="1" (ngModelChange)="minimumRange=$event" placeholder="0.0" step="0.1" type="number">
For more info:
Hope it helped! Good coding bro!
Update:
If we use @Pipe in model like this:
<input [(ngModel)]="myModel| uppercase">
It will throw the following error:
Parser Error: Cannot have a pipe in an action expression at column X
We will just need to change it to this:
<input [ngModel]="myModel| uppercase" (ngModelChange)="myModel=$event">
Update2:
Added (ngModelChange)="minimumRange=$event" to keep the two way binding functionality.
As @n00dle pointed me, removing the () removes the 2 way binding functionality. So the way to use @Pipe in a 2-way-binding would be using also (ngModelChange).
This could be of huge use:
pipes are not allowed in 2-way data-binding? @n00dl3action expression, but if we just change [(ngModel)] to [ngModel] it lets us apply the @Pipe.try this
<input [(ngModel)]="minimumRange" min="1" placeholder="0.0" step="0.1" type="number" (keyup)='conversion()'>
conversion(){
this.minimumRange = this.minimumRangex.toPrecision(2);
}
this.minimumRangex come from? Thanksthis.minimumRange
@Pipe. For example: stackoverflow.com/questions/38456114/…minimumRangea string or a number ?"1.0"is1...