AngularJS - 将参数传递给自定义指令中的过滤器
AngularJS - Pass parameter to filter in custom directive
我试图将参数(true、false)传递给自定义指令中的过滤器,但我总是得到 'undefined'。
<job jobs="jobs" activateFilter="activateFilter">
在控制器中(customDirective 之外):
$scope.activateFilter = true;
这是指令:
...
restrict: 'E',
scope: {
jobs: "=jobs",
activateFilter: "=activateFilter"
},
controller: controller,
templateUrl: "/views/templates/job.html"
...
这是模板:
... data-ng-repeat="job in jobs | customFilter:activateFilter ...
知道我做错了什么吗? activateFilter 始终未定义。
谢谢!!
尝试将属性名称设置为小写和破折号分隔:
<job jobs="jobs" activate-filter="activateFilter">
请参阅规范化和隔离指令范围下的 this
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.
我试图将参数(true、false)传递给自定义指令中的过滤器,但我总是得到 'undefined'。
<job jobs="jobs" activateFilter="activateFilter">
在控制器中(customDirective 之外):
$scope.activateFilter = true;
这是指令:
...
restrict: 'E',
scope: {
jobs: "=jobs",
activateFilter: "=activateFilter"
},
controller: controller,
templateUrl: "/views/templates/job.html"
...
这是模板:
... data-ng-repeat="job in jobs | customFilter:activateFilter ...
知道我做错了什么吗? activateFilter 始终未定义。 谢谢!!
尝试将属性名称设置为小写和破折号分隔:
<job jobs="jobs" activate-filter="activateFilter">
请参阅规范化和隔离指令范围下的 this
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.