How to format model variable of md-datepicker in particular format. I tried config of $mdDateLocaleProvider
, But it just formatted the display value of date-picker, not the model value. Please look at this codepen or below code:
HTML:
<div ng-app="MyApp" ng-controller="AppCtrl">
<md-content>
<md-datepicker ng-model="myDate" md-placeholder="Enter date"></md-datepicker>
</md-content>
<p>Date not formatted:</p>
{{myDate}}
</div>
JS:
angular.module('MyApp')
.controller('AppCtrl', function($scope) {
$scope.myDate = new Date();
})
.config(function($mdDateLocaleProvider) {
$mdDateLocaleProvider.formatDate = function(date) {
return moment(date).format('YYYY-MM-DD');
};
});