【发布时间】:2016-01-08 16:34:57
【问题描述】:
如何以特定格式格式化md-datepicker 的模型变量。我尝试了$mdDateLocaleProvider的配置,但它只是格式化了日期选择器的显示值,而不是模型值。请查看此codepen 或以下代码:
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');
};
});
【问题讨论】:
标签: javascript angularjs datepicker angular-material