1
正如标题所示,我在使用嵌套自定义指令的Angular项目上遇到了一些问题。我正在创建一个界面,允许用户通过点击复选框来过滤搜索结果的JSON订阅源。 该指令模板的层次结构如下:Angular JS - 使用ControllerAs和嵌套自定义指令
<filtergroup>
<filter></filter>
</filtergroup>
我似乎能够访问模板里的filtergroup指令的控制器定义的变量为filtergroup。但是我不能从孩子指令中访问相同的变量,尽管使用
require: '^filtergroup'
下面是我的指令:
.directive('filtergroup', [function(){
return{
restrict: 'E',
transclude: true,
scope: { },
template: '<div><ng-transclude></ng-transclude>{{filtergroup.variable}}</div>',
bindToController: true,
controllerAs: 'filtergroup',
replace: true,
controller: function() {
var self = this;
self.variable = "blah";
}
};}])
.directive('filter', [function(){
return {
restrict: 'E',
template: '<div>{{filtergroup.variable}}</div>',
require: '^filtergroup',
scope: {},
link: function(scope, elem, attr, filtergroupCtrl){
scope.active = false;
}
};}]);
我还创建了问题的简化Codepen在:
http://codepen.io/decodedcreative/pen/NrNqXm
任何帮助将是伟大的,因为这是让我疯了!谢谢
非常感谢您的帮助。我永远不会解决这个问题。的确,Angular具有相当的学习曲线! –