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