Change format of md-datepicker in Angular Material with momentjs

前端 未结 13 832
再見小時候
再見小時候 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:42

    Using $filter instead of moment.js and in reference to responses from @Ian Poston Framer and @java dev for me the following finally worked for me:

    angular
        .module('App', ['ngMaterial'])
        .run(function($mdDateLocale, $filter) {
            $mdDateLocale.formatDate = function(date) {
                return $filter('date')(date, "dd-MM-yyyy");
            };
        })
    

    I couldn't inject $filter into.config because it's not a provider, so I had to do it inside .run with $mdDateLocale.

提交回复
热议问题