Is there an equivelent to the “polymer-ready” event in Polymer 1.0?

孤街浪徒 提交于 2019-12-10 10:38:24

问题


I need to know when I can begin using my custom Polymer elements programmatically. The elements are still undefined even in my window.onload handler. Is there an established way of doing this correctly with Polymer 1.0?

-Edit-

I see there is a downvote, so let me clarify the issue. I have the following custom element definition:

<link rel="import" href="../../bower_components/polymer/polymer.html">

<dom-module id="element-one">
    <style>
        :host { display: block; background-color: blue; }
    </style>
    <template>
        <h1>Element One</h1>
        <content></content>
    </template>
</dom-module>

<script>
var ElementOne = Polymer({
    is: "element-one"
});
</script>

I then import this in my index.html:

<link rel="import" href="elements/element-one/element-one.html">

And at the bottom of index.html, before the </body> tag, I try to instantiate a ElementOne element:

<script>
    console.log(typeof ElementOne); // undefined
    var el = new ElementOne(); // fails, obviously

    // try on window load
    window.onload = function () {
        console.log(typeof ElementOne); // undefined
    };
</script>

I should note that this issue occurs in the latest Firefox and IE 10/11, but not in Chrome.


回答1:


use WebComponentsReady event:

window.addEventListener('WebComponentsReady', function(e) {
...
});


来源:https://stackoverflow.com/questions/30667685/is-there-an-equivelent-to-the-polymer-ready-event-in-polymer-1-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!