【发布时间】:2013-08-14 12:35:39
【问题描述】:
我在对多个指令的元素使用 ng-transclude 时遇到问题。
我有两个指令,其中一个实例化另一个:
//Basic first directive, checks if the second should be instantiated
app.directive('configModal', ['$compile', function($compile){
return {
restrict: 'C',
scope: {
manage: '=manage',
},
controller: function($scope, $element, $attrs, $transclude) {
//used to instantiate the second directive which is 'C' restricted
$element.addClass('widget-config-managed');
$compile($element);
};
}
};
}]);
//Second directive, has two wrap the content of the element by transclusion
app.directive('configManaged', ['$compile', function($compile){
return {
restrict: 'C',
template: '<div ng-transclude>Some more content</div>',
transclude: true,
compile: function(element){
console.log('compile from managed');
}
};
}]);
HTML 看起来像这样:
<div class="widget-config-modal">
<div>
Just some div.
</div>
问题在于 div 的原始内容:
<div>
Just some div.
</div>
没有被嵌入,而是被模板完全覆盖。
如何修复嵌入?
【问题讨论】:
-
尝试
replace: false为您的 configManaged 指令。 -
您是否尝试在“configManaged”指令配置中使用“replace: false”?也看看这个github.com/angular/angular.js/issues/2235
-
我尝试了'replace: false',但似乎没有什么不同。
标签: javascript angularjs angularjs-directive transclusion