0

I'm trying to format the value of an input field while I am typing into it.

<input (change)="test()" [(ngModel)]="testModel">

When I am trying this:

test() {
this.testModel = 2;
}

I would expect the visible text of my input to change to 2 on every input change. But nothing really is happening except the first character changes and console tells me the text did change (not visible though).

While when I am trying this:

test() {
this.testModel += 'a';
}

it works perfectly and adds an 'a' to the value on every type.

I'm trying to achieve that 1200 becomes 1.200€ while I am typing 1200. Thanks

Jan V.
  • 180
  • 3
  • 12
  • 4
    you should probably use an input mask instead – mast3rd3mon Mar 06 '19 at 16:48
  • I recommend reading the angular reactive-forms tutorial: https://angular.io/guide/reactive-forms also nice in this context https://angular.io/guide/form-validation – nologin Mar 06 '19 at 16:50
  • 1
    So I found a solution here: https://stackoverflow.com/a/37887432/5477412 Thx to @mast3rd3mon – Jan V. Mar 29 '19 at 13:02

0 Answers0