0

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!!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Solution: $scope.activateFilter = true; <job jobs="jobs" activate-filter="activateFilter"> Directive: activateFilter: "=activateFilter", data-ng-repeat="job in jobs | jobfilter:activateFilter"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.