Title: Passing filter to directive from controller angularjs
Tags: angularjs;angularjs-directive
Question: I have a directive called ```myCustomDirective``` and it takes a list of value and a filter function.

```myapp.directive('myCustomDirective', function ($rootScope) {
     return {
        replace: true,
        restrict: 'E',
        scope: {
            values: "=",
            customfilter: "&amp;"
          },
        templateUrl: '/Scripts/template.html',
        link: function (scope, elm, attr) {
        }
    }
});
```

And in my directive template ```template.html```, I have a simple list which will be filtered as filter function the directive got from client code.

```<tbody&gt;
    <tr ng-repeat="item in values | filter:customFilter&gt;
       <td ng-repeat="key in displaykey"&gt;{{item.name}}</td&gt;
    </tr&gt;
</tbody&gt;
```

In my controller, the custom function is

```$scope.myCustomFilter = function(value)
{
  return function(item)
   {
     if(item.name contains value) return true;
     return false;
    }
}
```

From HTML of client code, I want to pass the value and function by which the directive will filter the list.

```<div&gt;
  <my-custom-directive customfilter="myCustomFilter("a")"&gt;</my-custom-directive&gt;
</div&gt;
```

How can I get it right?

Comment: Its good to do filtering in directive itself , rather than in html  and making code complex

Comment: So, what is the problem? What's not working? Any error messages?

Comment: @Pop-A-Stash No error actually, but the list is not filtered as expected.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2018:00:04/24/18', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<angularjs><angularjs-directive>', 'Title': 'Passing filter to directive from controller angularjs', 'ViewCount': 32, 'id': 50009314, 'user_AboutMe': '<p>I am a mathematics enthusiastic, a problem solver, and a software engineer by profession.</p>\n', 'user_AccountId': 1425810.0, 'user_DisplayName': 'Moshi', 'user_Reputation': 1298.0, 'user_Views': 318.0, 'user_id': 1349365.0}}