2

I'm using the following filter inside a h3:

{{ event.date | date:'dd-MM-yyyy' }}

And is working just fine, the angular is formatting and showing the date like I want. I'm trying to apply the same filter inside an ng-model:

ng-model="event.date | date:'dd-MM-yyyy'"

And this is not working, is throwing an error:

Error: ngModel:nonassign
Non-Assignable Expression
Expression 'event.date' is non-assignable. Element: {1}

Could you someone explain me why?

Thanks!

Samurai Jack
  • 2,985
  • 8
  • 35
  • 58

2 Answers2

1

That is not possible the way you are trying to do.

An alternate solution will be using input masking. There are some libraries available already for the task such as ngMask and angular-input-masks.

https://github.com/candreoliveira/ngMask

https://github.com/assisrafael/angular-input-masks

atinder
  • 2,080
  • 13
  • 15
0

From the documentation:

The ngModel directive binds an input,select, textarea (or custom form control) to a property on the scope

https://docs.angularjs.org/api/ng/directive/ngModel

ng-model needs a variable that it can 2-way data-bind to but the filters output is not assignable.

clintsmith
  • 695
  • 6
  • 16