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

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

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest