简体   繁体   English

如何使Angular Directive模板包装内容(指令元素的子元素)

[英]How to make Angular Directive templates wrap content (child elements of the directive element)

I've googled a bit and I can't find anything that details how to make Angular directives that wrap content dynamically (for example http://demos.telerik.com/kendo-ui/panelbar/angular ). 我已经在Google上搜索了一下,但是找不到任何详细信息说明如何使Angular指令动态地包装内容(例如http://demos.telerik.com/kendo-ui/panelbar/angular )。 I'm not very familiar with transclusion, but my understanding is it has more to do with how the Angular scopes fit together than how the HTML fits together. 我对嵌入不是很熟悉,但我的理解是,与Angular范围如何组合在一起比与HTML如何组合更多有关。

Is the best way to just do a lot of DOM manipulation during the compile step? 是在编译步骤中进行大量DOM操作的最佳方法吗? Or is there some way to use template functions to accomplish it? 还是有某种方法可以使用模板函数来完成它?

EDIT: To give an example, I want this: 编辑:举个例子,我想要这个:

<directive>
    <div id="firstChild"></div>
    <div id="secondChild"></div>
</directive>

to compile to: 编译为:

<directive>
    <div id="firstTemplateElement">
        <div id="firstChild"></div>
    </div>
    <div id="secondTemplateElement>
        <div id="secondChild"></div>
    </div>
</directive>

You could do alot of dom manipulation, but what it seems you are trying to do is provide a new template for each item inside the directive. 您可以进行很多dom操作,但是您似乎想尝试的是为指令中的每个项目提供一个新模板。 No reason you can't make each item a directive too. 没有理由也不能使每个项目都成为指令。

<directive>
    <directive-item id="firstChild"></directive-item>
    <directive-item id="secondChild"></directive-item>
</directive>

compiles to: 编译为:

<directive>
    <directive-item id="firstTemplateElement">
        <div id="firstChild"></div>
    </directive-item>
    <directive-item id="secondTemplateElement>
        <div id="secondChild"></div>
    </directive-item>
</directive>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM