最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript: How to utilize angular $filter within custom filter - Stack Overflow

programmeradmin0浏览0评论

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]);
}

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]);
}
Share Improve this question asked Oct 21, 2015 at 16:28 Shyamal ParikhShyamal Parikh 3,0684 gold badges39 silver badges82 bronze badges 3
  • @PSL Thanks a lot, it did resolve the issue. Also it would be great if you can further clarify what you mean by //Here use $filter or filterFilter itself . I utilized this successfully: //public static Factory($filter: ng.IFilterService) – Shyamal Parikh Commented Oct 23, 2015 at 7:05
  • @PSL FYI your stackoverflow linkedin link is broken points to wrong address. – Shyamal Parikh Commented Oct 23, 2015 at 7:10
  • 1 Yes what i meant is if you are using $filter('filter') to get the built in fiter function you could as well inject filterFilter instead of $filter. – PSL Commented Oct 23, 2015 at 15:20
Add a ment  | 

1 Answer 1

Reset to default 7

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
} 
发布评论

评论列表(0)

  1. 暂无评论