简体   繁体   English

Polymer 1.0在其中添加其他聚合物元素

[英]Polymer 1.0 add other polymer elements inside

Hello what is the difference of doing adding a child polymer element like this: 你好,添加这样的子聚合物元素有什么区别:

<dom-module id="app-element">
    <template>
        <h1>Hello</h1>
        <test-element></test-element>
    </template>
    <script>
        Polymer({
            is: "app-element"
        });
    </script>
</dom-module>
<app-element></app-element>

This works just fine. 这很好用。 The effect of adding html code (including other polymer elements) inside the app-element tag 在app-element标记内添加html代码(包括其他聚合物元素)的效果

<app-element>some html here</app-element>

like this: 像这样:

 <dom-module id="app-element">
    <template>
        <h1>Hello</h1>

    </template>
    <script>
        Polymer({
            is: "app-element"
        });
    </script>
</dom-module>
<app-element>
    <test-element></test-element>
</app-element>

This ignores the test-element code. 这忽略了测试元素代码。 So in which cases can I add html code inside a polymer element? 那么在哪些情况下我可以在聚合物元素中添加html代码? When will it be ignored? 什么时候会被忽略? What would be the case where you want to add polymer elements inside other polymer elements inside the html code like this: 如果你想在html代码中的其他聚合物元素中添加聚合物元素会是这样的情况:

<app-element>
    <test-element></test-element>
</app-element>

?? ?? Thank you 谢谢

In your first case you are using local dom , in the second light dom . 在你的第一个案例中,你在第二个灯光dom中使用本地 dom In local dom, the custom element that contains it is responsible for the content (in this case app-element). 在本地dom中,包含它的自定义元素负责内容(在本例中为app-element)。 So the creator of the custom element decides the content of the local dom. 因此,自定义元素的创建者决定了本地dom的内容。 In contrast, using light dom provides the user of the custom element with the option to specify the content. 相反,使用light dom为自定义元素的用户提供了指定内容的选项。 The creator of the custom element can specify where the light dom should go inside the custom element using the <content></content> tag. 自定义元素的创建者可以使用<content></content>标记指定灯光dom在自定义元素内的位置。 So to make your second example work you would need something like this: 所以为了使你的第二个例子工作,你需要这样的东西:

<dom-module id="app-element">
    <template>
        <h1>Hello</h1>
        <content></content>
    </template>
<script>
    Polymer({
        is: "app-element"
    });
</script>
</dom-module>
<app-element>
    <test-element></test-element>
</app-element>

An example use case for light dom is the paper-dialog . 光dom的示例用例是纸对话框 Using light dom, the user of the dialog can decide the content of the dialog. 使用light dom,对话框的用户可以决定对话框的内容。 For example, the specific buttons to use, the main content of the dialog, etc. Have a look at this page in the documentation for more information on local and light dom. 例如,要使用的特定按钮,对话框的主要内容等。有关本地和轻量dom的更多信息,请查看文档中的此页面

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

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