AngularJS - 将参数传递给自定义指令中的过滤器

时间:2021-07-20 20:32:56

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

我试图将参数(true,false)传递给自定义指令中的过滤器,但我总是得到一个'undefined'。

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

In a controller (outside of customDirective):

在控制器中(在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!!

我有什么想法我做错了吗? activateFilter始终未定义。谢谢!!

1 个解决方案

#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.

注意:指令范围选项中的这些= attr属性与指令名称一样被规范化。要绑定到div bind-to-this =“thing”中的属性,您需要指定= bindToThis的绑定。

#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.

注意:指令范围选项中的这些= attr属性与指令名称一样被规范化。要绑定到div bind-to-this =“thing”中的属性,您需要指定= bindToThis的绑定。