gpt4 book ai didi

javascript - 多个指令和 ng-transinclude

转载 作者:行者123 更新时间:2023-11-28 08:57:33 25 4
gpt4 key购买 nike

我在多个指令的元素上使用 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>

没有被模板嵌入,而是完全被模板覆盖。

如何修复嵌入问题?

最佳答案

我认为你的指令不起作用。您不能在指令前加上 widget- 前缀。 。如果您愿意,可以在其前面加上 x- 前缀。或data-

所以<div class="widget-config-modal">不工作。

相反,您可以执行以下操作:

<div class="config-modal">
<!-- OR -->
<div class="data-config-modal">
<!-- OR -->
<div class="x-config-modal">

关于javascript - 多个指令和 ng-transinclude,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18231927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com