我正在努力围绕如何让ng-include不使用额外的DOM元素,因为我正在从纯HTML演示中构建一个角度应用程序。我正在使用完全开发,紧密DOM耦合CSS(由SASS构建)的非常苗条的HTML,重构是我想要不惜一切代价避免的。避免在使用nginclude时使用额外的DOM节点
下面是实际的代码:
<div id="wrapper">
<header
ng-controller="HeaderController"
data-ng-class="headerType"
data-ng-include="'/templates/base/header.html'">
</header>
<section
ng-controller="SubheaderController"
data-ng-class="subheaderClass"
ng-repeat="subheader in subheaders"
data-ng-include="'/templates/base/subheader.html'">
</section>
<div
class="main"
data-ng-class="mainClass"
data-ng-view>
</div>
</div>
我需要<部分>是一个重复的元素,但有其自身的逻辑和不同的内容。内容和重复次数都取决于业务逻辑。如您所见,将ng-controller和ng-repeat放在<部分的>元素将不起作用。然而,什么会插入一个新的DOM节点,这正是我想要避免的。
我错过了什么?这是最佳做法还是有更好的方法?
编辑:我只想澄清的问意见,我想生成最终的HTML是:
<div id="wrapper">
<header>...</header>
<section class="submenuX">
some content from controller A and template B (e.g. <ul>...</ul>)
</section>
<section class="submenuY">
different content from same controller A and template B (e.g. <div>...</div>)
</section>
<section class="submenuZ">
... (number of repetitions is defined in controller A e.g. through some service)
</section>
<div>...</div>
</div>
我之所以要使用相同的模板B(子头.html),代码清洁。我设想subheader.html有一些ng切换为了返回动态内容。
但基本上,下层quiestion是:有没有一种方法可以透明地包含模板的内容,而不使用DOM节点?
EDIT2:该解决方案需要是可重复使用的。 =)
你可以添加一个变体的例子,现在确定你在问什么? – Chandermani
对不起。编辑澄清。 –
您可以使用ng-include作为标签' ',而不是除了发布'url'的内容外的其他标签。 –
Chandermani