为什么我的聚合物母体成分在孩子面前准备好

时间:2016-07-26 18:19:51

标签: templates polymer lifecycle ready

与聚合物的文档相反,表明聚合物子组件将在父母之前准备就绪,我可以在我的代码中看到root-component的ready()方法在main-box(子)代码ready()方法之前被调用被召唤。输出是“root ready,main ready”。当我在root-component(dom-if模板)中注释掉条件模板时,我得到“main ready,root ready”。我不知道为什么会这样。 utk变量目前硬编码为true,因此它不像以后出现的根组件。

我有一个index.html,它有脚本和紧凑的小体:

    <body>
       <root-component></root-component>
    </body>

根部成分是一种大型聚合物成分,直到我将其剥离以了解问题所在:

    <dom-module id="root-component">
       <template>
         <template is="dom-if" if={{utk}}> <--- UNCOMMENT THIS INNER TEMPLATE TAG AND ITS END TAG AND YOU WILL SEE main-section-box IS READY BEFORE root-component
           <main-box></main-box>
         </template>
       </template>
      <script> 
         // defines polymer root-component here, defines utk property as true, ready method prints out "root ready" 
      </script>
    </dom-module>

最后一个主框,只打印出“HI”:

    <dom-module id="main-box">
      <template>HI</template>
      <script> 
         // defs polymer main-box here, ready method prints out "main ready"
      </script>
    </dom-module>

请帮助我理解为什么会这样。

我正在尝试确定孩子何时准备就绪,这样我就可以在他们注意的时候向他们发出信号(不要让他们错过信号),但是因为它似乎已经成为根源在孩子面前做好准备,依靠ready()可能不如我想象的那么可靠。

请注意,此问题与Parent element is ready before its child - Polymer 1.0不同。

0 个答案:

没有答案