Search code examples
javascriptangularjsangularjs-filterangular-filtersdatefilter

Angular Date Filter's format section not working


I want to show date with format 'MM/dd/yyyy'.
The date filter working but that format of date part doesn't working.

the following one is my code:

this.$filter('date')(this.BeginDate, 'MM/dd/yyyy')

Solution

  • here is a quick example of what you need, check the way you call the filter in your controller

    angular.module('myApp',[])
    .run(function($rootScope,$filter){
    
      $rootScope.date = $filter('date')(new Date(),'MM/dd/yyyy'); // the issue is here
    })
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="myApp">
      {{date}}
    </div>