Max Berg
Max Berg

Reputation: 95

AngularJS - Pass parameter to filter in custom directive

I'm trying to pass a parameter (true, false) to a filter in a custom directive, but I always get an 'undefined'.

<job jobs="jobs" activateFilter="activateFilter">

In a controller (outside of customDirective):

$scope.activateFilter = true;

This is the directive:

...
restrict: 'E',
        scope: {
            jobs: "=jobs",
            activateFilter: "=activateFilter"
        },
        controller: controller,
        templateUrl: "/views/templates/job.html"
...

And this is the template:

... data-ng-repeat="job in jobs | customFilter:activateFilter ...

Any ideas what I'm doing wrong? activateFilter is always undefined. Thanks!!

Upvotes: 0

Views: 1113

Answers (1)

eladcon
eladcon

Reputation: 5825

Try to set the attribute name to lower case and dash-delimited:

<job jobs="jobs" activate-filter="activateFilter">

See this under Normalization and Isolating the Scope of a Directive

Note: These =attr attributes in the scope option of directives are normalized just like directive names. To bind to the attribute in div bind-to-this="thing", you'd specify a binding of =bindToThis.

Upvotes: 1

Related Questions