如何在自定义过滤器中使用角度$ filter?如何注入$ filter依赖?
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]);
}
答案 0 :(得分:7)
您可以注入$filter
并使用ng.IFilterService
类型或专门使用filterFilter
(如果您正在寻找$filter('filter')
)并使用Function
类型。< / p>
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
}