0

If the name of the filter is static, you can just inject the name of the filter with "Filter" appended to it into your component's controller function, like this:

angular.module('ngApp').component('myComponent', {
    bindings: {
        dynamicFilter: '@'
    },
    controller: [
        'staticFilterFilter',
        function(staticFilterFilter) {
            this.valueSetByStaticFilter = staticFilterFilter('x');
        }]
});

Is there a way to pass the name of a filter into an angularjs version 1.6 component as bound as argument/attribute string using '@' and then be able to get that filter by name and use it inside of the controller of that component?

Mistalis
  • 17,793
  • 13
  • 73
  • 97
bkinsey808
  • 2,669
  • 3
  • 16
  • 20

1 Answers1

0

Inject the $filter service into the component's Controller. You can then retrieve and use the filter by doing something like this:

var filtered = $filter('yourFilterName')(arg1,arg2);

So in your code change it to something like:

angular.module('ngApp').component('myComponent', {
    bindings: {
        dynamicFilter: '@'
    },
    controller: [
        '$filter',
        function($filter) {
            var filtered = $filter(this.dynamicFilter)(arg1,arg2);
        }
    ]
});
Matthew Cawley
  • 2,688
  • 1
  • 8
  • 19