问题
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