Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot have a pipe in an action expression ?

Tags:

I'm using this statement in my html template:

[(ngModel)]="tempProduct.unitprice | number : '1.2-2'" 

But when i run it im getting this error in console:

Cannot have a pipe in an action expression...

I need to use this number pipe but with [(ngModel)] or i will not get data. Any suggestion how can i fix this?? I tried with [ngModel] but when i do that i dont get data, its empty in html template.

like image 279
None Avatar asked Sep 04 '17 16:09

None


People also ask

Can I use pipe in ngModel?

To use pipes within ngModel on input elements in Angular, we can use separate [(ngModel)] into [ngModel] and (ngModelChange) . to apply the useMyPipeToFormatThatValue pipe to item. value in ngModel . Then we handle our input change events in ngModelChange .

Can I use pipe for input field angular?

A pipe takes in data as input and transforms it into a different shape for displaying. Pipes are simple functions to use in template expressions to accept an input value and return a transformed value. Pipes are useful because you can use them throughout your application, while only declaring each pipe once.

How do you use custom pipes?

Steps Involved In Creating a Custom Pipe In Angular are: 1) Create a Pipe Class and decorate it with the decorator @Pipe. 2) Supply a name property to be used as template code name. 3) Register your Pipe in the module under declarations. 4) Finally, implement PipeTransform and write transformation logic.


1 Answers

Perhaps this should work for you:

[ngModel]="tempProduct.unitprice | number : '1.2-2'" (ngModelChange)="tempProduct.unitprice = $event" 

This way "two-way"-binding is split in property-binding and event binding which allows more complex expressions.

like image 128
Günter Zöchbauer Avatar answered Sep 17 '22 12:09

Günter Zöchbauer