如何在模板中显示html? [英] How to display html inside template?

查看:134
本文介绍了如何在模板中显示html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有聚合物元素:

示例



默认模板不允许插入html。



这个示例不起作用,因为它不允许插入html。
也许存在这样做的方法。

解决方案

执行此操作的一种方法是通过 *更改观察者并设置 .innerHTML 节点:

 < div id =div>< / div> 

labelChanged:function(){
this。$。div.innerHTML = this.label;
}

然后,对于< template repeat> 大小写,将其包装在一个遵循相似模式的自定义元素中: https://stackoverflow.com/a/22208332


I have polymer-element:

example

By default templates is not allowed to insert html.

This sample is not working, because it's not allowed to insert html. Maybe exists the way to do that.

解决方案

One way to do this is through a *Changed watcher and setting the .innerHTML the node:

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

labelChanged: function() {
  this.$.div.innerHTML = this.label;
}

Then, for the <template repeat> case, wrap things up in a custom element that follows the similar pattern: https://stackoverflow.com/a/22208332.

这篇关于如何在模板中显示html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆