angularjs – 如何递归要求访问父指令的控制器?
发布时间:2020-12-17 08:13:24 所属栏目:安全 来源:网络整理
导读:我正在递归地到达父“框”指令的控制器: body ng-app="main"!-- no nesting: parent is the just body --box/boxscript type="text/javascript"angular.module('main',[]).directive('box',function() { return { restrict: 'E',controller: function() { }
我正在递归地到达父“框”指令的控制器:
<body ng-app="main"> <!-- no nesting: parent is the just body --> <box></box> <script type="text/javascript"> angular.module('main',[]) .directive('box',function() { return { restrict: 'E',controller: function() { },require: '?^box',// find optional PARENT "box" directive link: function(scope,iElement,iAttrs,controller) { // controller should be undefined,as there is no parent box alert('Controller found: ' + (controller !== undefined)); } }; }); </script> </body> 我期望控制器变量在链接函数中未定义,但是我得到了实际框指令的控制器。 所以我的问题是…如何获得对PARENT控制器的访问情况,如下所示: <box> <box></box> </box> http://jsfiddle.net/gjv9g/1/
由于Angular 1.3,您可以使用两个口音^^在父元素“only”中搜索指令。
报价从Angular Docs on
在你的情况下,替换require:’?^ box’,需要:’?^^ box’, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |