0
<input [value]="control.value" currencyMask [id]="control.fieldId" [type]="text" (keypress)="onkeypress($event)">

The above field is supposed to be currency field. I am using currencyMask to format the field value as the user enters. But when the value is passed to the input from backend(to be shown as a pre-filled data), it doesnt get formatted.

So i am thinking to implement a pipe which formats the value in both cases. But i have no proper way to implement that.

I tried as:

input [value]="{{control.value | customPipe}}" currencyMask [id]="control.fieldId" [type]="text" (keypress)="onkeypress($event)"

it was throwing an error as unexpected {{}}

I am open to any better suggestions

radio_head
  • 1,306
  • 4
  • 13
  • 28
  • You can't have a pipe on input tag, but you can call it in component and use `.transform()`. – developer033 Jun 01 '17 at 13:50
  • will that change the value of the model..i want the model to be plain number without commas and dollar – radio_head Jun 01 '17 at 14:15
  • @developer033 its bnot advisable to call a pipe inside a component – Rahul Singh Jun 02 '17 at 06:03
  • @RahulSingh out of curiosity.. where did you find this? Why isn't It advisable? – developer033 Jun 02 '17 at 09:39
  • @developer033 pipes are meant to transform a value in the template without modfying the exact value of the model. if you want to acheive something like this then go for service method or any other function – Rahul Singh Jun 02 '17 at 09:43
  • @RahulSingh again.. any resource of this? Where did you find that it isn't advisable? – developer033 Jun 02 '17 at 09:45
  • @developer033 no i dnt have but i have come across it some time i rememeber that , if this wasnt the case why do we have services everything can be in pipes right ? – Rahul Singh Jun 02 '17 at 09:47
  • How would a service help in this case? To format input? He wants something to format input.. people could suggestion directives, and yes, *Pipes* in component. I really don't know why you're saying that isn't advisable. – developer033 Jun 02 '17 at 09:54

0 Answers0