Formatting numbers by type in an input field in Angular2 with double binding

With pipes like

<input....
    [ngModel]="whatever | myCurrencyPipe"
    (ngModelChange)="whatever = $event"
    type="text"
    name="myCurreny"
    ...

You can format the existing value. You rarely want to rewrite the meaning; you have problems. And with the solution above, double binding is canceled.

There are many jQuery-Libraries , but I am looking for my own angular2 solutions.

Can someone help me?

+4
source share
1 answer
  • Extend the NgModel directive. Rewrite the viewToModelUpdate (value) function that is called after each change to the input and setting the model value.
  • Replace NgModel with your implementation (providers [] in the module)
  • regexp , , : < = "" /" >

: http://stacktrase.com/2017/07/14/angularjs4-restrict-input-text-by-extending-ngmodel/

+1

Source: https://habr.com/ru/post/1657722/


All Articles