是否有与“聚合物就绪"相当的产品? 1.0中发生的事件? [英] Is there an equivelent to the "polymer-ready" event in Polymer 1.0?
问题描述
我需要知道何时可以开始以编程方式使用自定义的Polymer元素.即使在我的window.onload
处理程序中,元素仍然是undefined
.可以使用Polymer 1.0正确地做到这一点吗?
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?
-编辑-
我看到有人投票了,所以让我澄清一下这个问题.我有以下自定义元素定义:
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>
然后我将其导入我的index.html
:
<link rel="import" href="elements/element-one/element-one.html">
在index.html
的底部,在</body>
标记之前,我尝试实例化ElementOne
元素:
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>
我应该注意,在最新的Firefox和IE 10/11中会发生此问题,但在Chrome中不会发生.
I should note that this issue occurs in the latest Firefox and IE 10/11, but not in Chrome.
推荐答案
使用 WebComponentsReady 事件:
window.addEventListener('WebComponentsReady', function(e) {
...
});
这篇关于是否有与“聚合物就绪"相当的产品? 1.0中发生的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!