Is there a way to allow safe html data bind in polymer?

穿精又带淫゛_ 提交于 2019-12-02 06:29:46

问题


Is there a way to allow data bind with html rendering in polymer?

For example in AngularJS there is the "ng-html-bind" directive that does the job. I am searching something similar.

Here it follows an example of where I am willing to use it.

<core-tooltip>
    <core-icon icon="info-outline" size="30"></core-icon>
    <div tip>
       {{box.description}}
    </div>
</core-tooltip>

Otherwise any suggestion on how to do it differently? I am loading this data from a json file and I am searching for a general way to allow "safe" html rendering (against XSS).


回答1:


This has been answered a couple of times:

  • How to inject HTML into a template with polymer
  • How to display html inside template?



回答2:


As suggested in the accepted answer, I associated an id to my tooltip div:

<div id="tipContent" tip>
    {{box.description}}
</div>

Then made my element listen to the box changes:

Polymer("nautes-box",{
  boxChanged: function(){
      this.$.tipContent.innerHTML = this.box.description.chunk(40).join("<br /><br />");
  }
});

I hope this answer will eventually be useful :)



来源:https://stackoverflow.com/questions/24950329/is-there-a-way-to-allow-safe-html-data-bind-in-polymer

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