我认为该元素在 IE11 中没有正确投影。看下面的例子:
<body unresolved>
<p>If this demo works correctly, you should be able to see the message <code>"Hello there. Hola!"</code></p>
<p>
This works as expected in all browsers except Internet Explorer 11 (maybe 10, although I didn't test). The issue is that when I assign helloElement.value, helloElement is not the same element that is being appended to the dome after is projected inside
the <demo-snippet>.
</p>
<demo-snippet>
<template is="dom-bind">
<hello-element></hello-element>
<script>
var helloElement = document.querySelector('hello-element');
helloElement.value = 'Hola!';
// Wait enough time to make sure demo-snipper is rendered properly
setTimeout(function() {
console.log(helloElement === document.querySelector('hello-element')) // this is true in all browsers. In IE11 is false.
}, 3000)
</script>
</template>
</demo-snippet>
</body>
所发生的情况是,在除 IE11 之外的所有浏览器中,helloElement.value
中分配的值都会被复制到 demo-snippet 元素内的投影元素中。这意味着,如果您添加一个就绪的处理程序并且您这样做
ready: function () {
console.log(this.value) // --> 'Hola!' except IE11, that is ''
}
将我的代码投影到其中时,这是 Polymer 或 demo-snippet 中的错误吗?或者什么时候附加到dom?我真的不知道:(
您可以在这个 Plunker 中使用我的示例:https://plnkr.co/edit/5UBCDjqC0A8k6HcaHnIJ?p=preview
最佳答案
显然 IE 对此更加严格。您需要调用 element.setAttribute
而不是仅仅将其添加到对象中。
这将确保 polymer 选择默认值作为属性。
关于javascript - <demo-snippet> 内的元素仅在 IE11 中无法正确克隆/投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39915765/