如何将聚合物填料一起使用

时间:2013-12-30 20:25:17

标签: javascript polyfills polymer shadow-dom

我正在尝试使用Polymer ShadowDOMCustom Elements

的{{3}}填充物

如果我单独使用它们,它们运行良好,但当我同时使用它们时,我会收到这样的错误

Uncaught TypeError: Cannot read property 'polymerShadowRoot_' of undefined.....Element.js:69

这取决于我是否首先包含customelement.js或shadowdom.js

这是我的测试代码:

<!doctype html>

<html>
  <head>

    <script src="/bower_components/CustomElements/custom-elements.js"></script>
    <script src="/bower_components/ShadowDOM/shadowdom.js"></script>

    <script>
      var proto = Object.create(HTMLElement.prototype);

      proto.createdCallback = function() {
        console.log('create shadowDOM');
        var root = this.createShadowRoot();
        root.innerHTML = '<content></content>';
      };

      document.register('x-foo', {prototype: proto});
    </script>
  </head>

  <body>
    <x-foo><span>hallo</span></x-foo>
  </body>
</html>

有什么建议可能会出错吗?

1 个答案:

答案 0 :(得分:1)

每当使用ShadowDOM polyfill时,必须首先加载它,因为它完全重新映射DOM。其他库(通常)可以在重映射之上加载,但不能在下面加载。

http://jsbin.com/uBOQIBu/3/edit