Angularjs 嵌套指令-链接和控制器函数不在子级中执行
我肯定我少了一些东西。 我有如下嵌套指令,加载文件时未执行子链接和控制器函数 我的index.html文件是:Angularjs 嵌套指令-链接和控制器函数不在子级中执行,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我肯定我少了一些东西。 我有如下嵌套指令,加载文件时未执行子链接和控制器函数 我的index.html文件是: <champ-table> <champ-column></champ-column> <champ-column></champ-column> <champ-column></champ-column> <champ-column></champ-c
<champ-table>
<champ-column></champ-column>
<champ-column></champ-column>
<champ-column></champ-column>
<champ-column></champ-column>
</champ-table>
和冠军桌
(function(){
angular.module('champ').directive('champTable',function(){
return {
restrict : 'E',
scope: {
table : '='
},
templateUrl : './app/directives/champTable/champ-table.tpl.html',
link : function(scope,element,attrs){
some code here...
}
};
});
})();
我在网上搜索了一段时间寻找解决方案,但只看到了结构与我类似的示例。所以这一定是我做错了或错过了什么。当然,不用说,我将脚本文件包括在索引文件中。
试图删除父元素中的作用域,但没有帮助。如果你有想法,那就太好了!谢谢大家! 请提供您的html:您是否编写了类似这样的内容:我猜
的模板正在覆盖内部
s。在
的定义中添加transclude:true
,并在其模板中添加
,子项应该放在模板中。在进一步调试指令之前,可能需要修复此问题:angular.module('champ')
如果没有依赖项,则包括空数组:angular.module('champ',[])
@NikosParaskevopoulos一个像魔术一样为我工作的家伙。最后我终于知道为什么我需要这个可怕的“transclude”短语了。@ShehryarAbbasi我使用了我在另一个文件中创建的一个应用程序实例。很抱歉没有提到这件事。
(function(){
'use strict';
angular.module('champ').directive('champColumn',function(){
return {
restrict : 'E',
controller : function(){
console.log('champ-column controller loaded');
},
link : function(scope,element,attrs){
console.log('champ-column linked');
}
};
});
})();
(function(){
angular.module('champ').directive('champTable',function(){
return {
restrict : 'E',
scope: {
table : '='
},
templateUrl : './app/directives/champTable/champ-table.tpl.html',
link : function(scope,element,attrs){
some code here...
}
};
});
})();