Note: This post applies to AngularJS. The 1.x version of Angular. AngularJS has been end of life at of 12/31/2021.

Here is a quick tip for how to call a filter from within your Angular controller. This example assumes that you already know what a filter is and have one created.

  1. Inject $filter into your controller

    angular.module('sample').controller('SampleController', SampleController);
    
    /* @ngInject */
    function SampleController($filter) {
    }
    
  2. Call your filter by calling:

    • View call your filter called “myFilter” on myDateVariable with arguments arg1 and arg2, you would use:
    <p>{{myDateVariable | myfilter : arg1 : 'arg2' }}</p>
    
    • Controller call the same filter from within your controller:
    function SampleController($filter) {
        var value = $filter("myFilter")(myDateVariable, arg1, arg2);
    }