angular - Using Pipes within ngModel on INPUT Elements in Angular2-View -


i've html input field.

<input [(ngmodel)]="item.value" name="inputfield" type="text" /> 

and want format value , use existing pipe:

.... [(ngmodel)]="item.value | usemypipetoformatthatvalue" ..... 

and error message:

cannot have pipe in action expression

how can use pipes in context?

you can't use template expression operators(pipe, save navigator) within template statement:

(ngmodelchange)="template statements" 

(ngmodelchange)="item.value | usemypipetoformatthatvalue=$event"

https://angular.io/docs/ts/latest/guide/template-syntax.html#!#template-expressions

so should write follows:

<input [ngmodel]="item.value | usemypipetoformatthatvalue"        (ngmodelchange)="item.value=$event" name="inputfield" type="text" /> 

plunker example


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -