Set an AngularJS date filter format to be used by all references to the date filter?

前端 未结 5 971
余生分开走
余生分开走 2021-02-18 18:03

Rather that having to define a custom format for each call to the date filter, is there a way to globally define a default format (other than \'medium\'

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-18 18:20

    Based on some more research and then considering the comment by moderndegree, I have found that the following myDate filter will work:

    .filter('myDate', function($filter) {    
        var angularDateFilter = $filter('date');
        return function(theDate) {
           return angularDateFilter(theDate, 'dd MMMM @ HH:mm:ss');
        }
    });
    

提交回复
热议问题