How to inject HTML into a template with polymer

前端 未结 3 1826
情话喂你
情话喂你 2020-11-27 06:42

I\'m using polymer-jsonp to perform JSONP requests, but the response sometimes contains html.

For example, supposing that post.content is \"Foo&l

3条回答
  •  死守一世寂寞
    2020-11-27 07:40

    If you're sure it is what you want to do, just use innerHTML.

    _renderHtml: function(html) {
      this.$.dynamicHtmlContainer.innerHTML = html;
    }
    

    Or to dynamically add a shadow-dom child:

    _renderHtml: function(html) {
      var div = document.createElement('div');
      div.innerHTML = html;
      Polymer.dom(this).appendChild(div);
    }
    

    I think Polymer.dom is being removed in Polymer 2.0 though.

提交回复
热议问题