-2

I would like to manipulate ngModel view like you can do $formatter / $parser in Angular 1.

My original idea is to do the following

<input type="text" [(ngModel)]="context.highQueuePriority" (ngModelChange)="appendPercent($event)" />

and with this function

appendPercent(val): string {
    this.context.highQueuePriority = val.replace(/^[a-zA-Z%]+/g, '') + '%';
}

to basically changes the view to 40% if user enters 40.

taropoo
  • 110
  • 2
  • 8
  • so what's the problem with this? – micronyks Nov 05 '16 at 04:36
  • I have 3 same input that requires the same function. I just wanna see if there's a better way to do this. Also I need to manipulate the data when I first get it and manipulate it again when I send it back. – taropoo Nov 05 '16 at 05:09

1 Answers1

0

I found a perfect article explaining how to do this. Posting it for anyone else that might come across it. https://blog.ngconsultant.io/custom-input-formatting-with-simple-directives-for-angular-2-ec792082976#.fp9qc9x9c

taropoo
  • 110
  • 2
  • 8