Reputation: 1583
I am binding input element with model property in angular 5
<input [(ngModel)]="MB.YearOfOperation | date: 'dd-MMM-yyyy' " type="text" class="form-control">
Using date pipe to format its value but it gives error
Cannot have a pipe in an action expression at column 33
so I tried below approach with (ngModelChange)
<input [(ngModel)]="MB.YearOfOperation | date: 'dd-MMM-yyyy' " (ngModelChange)="MB.YearOfOperation =$event" type="text" class="form-control">
But still it give the same error , How can I use pipes with [(ngModel)] ??
Upvotes: 2
Views: 8143
Reputation: 222582
You should not use pipe with two way databinding, if you really want to use it with ngModel, you should consider one way data binding with ngModelChange
as follows,
[ngModel]="MB.YearOfOperation | date: 'dd-MMM-yyyy'" (ngModelChange)="updateDate($event)"
Upvotes: 5