2
votes

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)] ??

1

1 Answers

5
votes

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)"