Looking for guidance on how to correctly format the model variable of md-datepicker in a specific format? I attempted to use the configuration settings of $mdDateLocaleProvider
, however, it only impacted the display value of the date-picker and not the model value. Please refer to this codepen example or see the code below:
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');
};
});