Polymer - how to create element with binding

别等时光非礼了梦想. 提交于 2019-12-24 02:33:34

问题


I need to create polymer custom element with binding attribute.

<foo-bar baz="{{qux}}"></foo-bar>

It's OK. But it must be created dynamically (tagName passed as an attribute). I try this

Polymer({
    ready: function() {
        var element = document.createElement(this.tagName);
        element.setAttribute('baz', '{{qux}}');
        this.$.placeholder.appendChild(element);
    }
});

But it does not work. How can I do that?


回答1:


You can do this with injectBoundHTML():

<div id="container"></div>

...

this.injectBoundHTML('<foo-bar baz="{{qux}}"></foo-bar>', this.$.container);

It's not documented yet, but more info is here: https://github.com/Polymer/docs/issues/607



来源:https://stackoverflow.com/questions/25981318/polymer-how-to-create-element-with-binding

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