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 injectfilterFilter
instead of$filter
. – PSL Commented Oct 23, 2015 at 15:20
1 Answer
Reset to default 7You 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
}