Cannot have a pipe in an action expression ?

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.

2 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.

3

Thanks! Fun fact: this works with ng2-dragula too!

<div [dragula]="'COPYABLE'" [dragulaModel]="service.model.players | PlayerFilterPipe: queryString" (ngModelChange)="service.model.players = $event"> <div *ngFor="let player of service.model.players | PlayerFilterPipe: queryString">{{player.name}}</div>

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like