Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript: How to utilize angular $filter within custom filter

How can I utilize angular $filter within a custom filter? How to inject $filter dependency?

module Filters {

    export class CustomFilter {
        public static Factory() {
            return function (input:<any>) {

                var result = [];

                //Would like to utilize $filter.('filter') here

                return result;
            }
        }
    }

    angular.module('app')
        .filter('customFilter', [CustomFilter.Factory]);
}
like image 757
Shyamal Parikh Avatar asked Oct 21 '15 16:10

Shyamal Parikh


1 Answers

You could just inject $filter and use type ng.IFilterService or specifically use filterFilter (if you are looking for $filter('filter')) and use type Function.

module Filters {
    export class CustomFilter {
        //Here use `$filter` or filterFilter itself
       //public static Factory($filter: ng.IFilterService)
        public static Factory(filter:Function) {
            return function (input:any) {

                var result = [];

                //filter is now $filter('filter')

                return result;
            }
        }
    }

    angular.module('app')
        .filter('customFilter', ['filterFilter', CustomFilter.Factory]);
        //Inject $filter for generic filter getter
} 
like image 114
PSL Avatar answered Nov 04 '22 20:11

PSL