Change format of md-datepicker in Angular Material with momentjs

前端 未结 13 779
再見小時候
再見小時候 2020-11-28 09:01

Angular material introduced a new date picker component found here.

I want the date returned by this component to be in the format yyy-mm-dd but I am not su

13条回答
  •  [愿得一人]
    2020-11-28 09:51

    -- When we use md-DatePicker in md-dialog then $mdDateLocaleProvider service doesnot format the date as we need. We have to use $mdDateLocale in controller of md-dialog to format the date of md-DatePicker. for example -

    angular.module('MyApp').controller('AppCtrl', function($scope, $mdDateLocale) {
    
      $mdDateLocale.formatDate = function(date) {
        return moment(date).format('YYYY-MM-DD');
      };
    
      $scope.myDate = new Date('2015-10-15');
    
      $scope.minDate = new Date();
    
      $scope.maxDate = new Date();
    });
    

提交回复
热议问题