- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在多个指令的元素上使用 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/
我在 StackOverflow 上看到了很多讨论 ng-transclude 的问题,但没有一个问题能通俗地解释它是什么。 文档中的描述如下: Directive that marks the in
我认为这是我用 angularjs 指令最难理解的概念之一。 来自http://docs.angularjs.org/guide/directive的文档说: transclude - compile
我在 AngularJS 1.5 中编写了一个名为“news”的自定义指令。 其布局如下: 该指令的 JavaScript 文件如下: return {
我在多个指令的元素上使用 ng-transclude 时遇到问题。 我有两个指令,其中一个指令实例化另一个指令: //Basic first directive, checks if the seco
我正在制作一个指令,其中包含一个加载的模板,以及一些传入的嵌入内容。所以本质上我的 html 是 Some transcluded content 但是,当我的页面加载时,有那么一瞬间我只
我有一个指令如下: 问题位于 ,其中item当内部 ng-repeat 时,将是当前迭代项的引用绑定(bind)在 内。 据我所知,嵌入似乎看不到指令
给定一个带有嵌入和隔离范围的指令(container1),当链接指令时,我有这些范围: Scope 004 但这不起作用,在 component1 内部,$scope.
我一直在互联网上寻找类似的东西,但仍然找不到答案。 我有一个在我的应用程序中重复使用的指令,它允许用户对项目列表进行排序和搜索。我有多种类型的项目可以传递到指令(我传递的 html 模板)以及这些模板
我创建了指令来通过单击 对表进行排序但无法正确排序函数执行。我的问题是如何按升序/降序对数据进行排序。该指令可以与任何静态或动态表链接,然后使用 tranluc 和 $compile 创建我们自己的
我有一个项目,我们使用了很多 Angular ui-select 指令。 ui-select 的使用是标准化的,我们使用它的各个点之间的唯一区别是 ui-select-choice 模板和用于获取结果
我尝试搜索有关 SO 的引用资料。但对答案不满意。我是 Angular 的新手。我试图通过创建这样的指令来实现嵌入: app.directive('wrapperDirective',function
我是一名优秀的程序员,十分优秀!