Reputation: 141
I'm trying to set the value of a "date" input but im getting this error message :
Error: [ngModel:datefmt] Expected `03/27/2012` to be a date
I was under the impression that the correct format was MM/DD/YYYY? ive also tried DD/MM/YYYY.
I'm using moment.js to format then setting the value of the textbox.
<label class="item item-input item-stacked-label">
<span class="input-label">Date Entered :</span>
<input type="date" placeholder="Date Entered" value="" ng-model="entered">
</label>
controller :
$scope.entered = moment($scope.entered).format("MM/DD/YYYY");
Upvotes: 1
Views: 553
Reputation: 471
You could do this:
dateobj = $scope.entered
var tempobj = {
year: dateobj.getFullYear(),
month: dateobj.getMonth(),
day: dateobj.getDate()
}
var momentobj = moment(tempobj).format('format it the way you want to');
Upvotes: 0
Reputation: 678
There is a library called angular-moment, where you can use a variety of filters.
Check it out: https://github.com/urish/angular-moment
Upvotes: 1