I want to add Commas to Input box while typing into in. how can we do that ? Currently I am trying to do it via onkeyup function converting that value to commas and then binding it to input but its not giving proper output.
Code I am Using :
<input type="text" (keyup)="getValueWithCommas($event)" matInput placeholder="Budget" formControlName="Budget" [value]="a">
getValueWithCommas(event){
this.a = event.target.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
but this is not working properly it placing commas in wrong places. But If I am binding this value to some span below input then its working correctly why is it so ?