【问题标题】:How to display html inside template?如何在模板中显示html?
【发布时间】:2014-03-10 21:22:34
【问题描述】:

我有聚合物元素:

example

默认情况下不允许模板插入 html。

This sample is not working,因为不允许插入html。 也许存在这样做的方法。

【问题讨论】:

    标签: html templates polymer


    【解决方案1】:

    一种方法是通过*Changed 观察者并设置.innerHTML 节点:

    <div id="div"></div>
    
    labelChanged: function() {
      this.$.div.innerHTML = this.label;
    }
    

    然后,对于 &lt;template repeat&gt; 的情况,将内容包装在遵循类似模式的自定义元素中:https://stackoverflow.com/a/22208332

    【讨论】:

      【解决方案2】:
      <element inner-h-t-m-l="{{prop}}"></element>
      

      适用于 Polymer 2。来源:https://github.com/Polymer/TemplateBinding/issues/57

      【讨论】:

        猜你喜欢
        • 2022-01-03
        • 1970-01-01
        • 2014-08-12
        • 2016-10-15
        • 1970-01-01
        • 2021-07-27
        • 2021-02-23
        • 2017-08-07
        • 2014-11-22
        相关资源
        最近更新 更多