Reputation: 157
I would like to display date in a format of 'yyyy-MM-dd' while saving the value in event.StartDate
If I remove the ng-model, it can show the correct date, which is '2017-01-26 12:00', but the value cannot be saved into event.StartDate.
However, if I add back the ng-model, the date format does not work and '/Date(1485403200000)/' is shown.
Here is my code.
<div ng-repeat="event in Events">
<input name="eventStartDate" type="text" ng-model="event.StartDate" value="{{event.StartDate.replace('/Date(','').replace(')/','') | date:'yyyy-MM-dd HH:mm'}}" />
</div>
Upvotes: 0
Views: 1901
Reputation: 6280
You need to apply the date filter to ng-model
and you don't need the value
attribute. Try with:
<input name="eventStartDate" ng-model="event.StartDate | date: 'yyyy-MM-dd'" type="text"/>
Upvotes: 3