我在多个指令的元素上使用 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>
没有被嵌入,而是被模板完全覆盖。
如何修复嵌入?