问题
view.html
<div>{{text}}</div>
The question is that 'text' has HTML that I wish to be displayed as it should but it only shows the HTML tags and text.
What can I do to render such content?
I've tried the earlier version (Ionic 1/2) solutions and nothing seems to work with Ionic v3.
回答1:
You should use the innerHTML
attribute binding like this:
<div [innerHTML]="text"></div>
Please take a look at the Angular docs for more information.
回答2:
in case you want to write it in paragraph you can do that by
<p><span [innerHTML]="htmlObject"></span></p>
<p><span>"{{title}}" is the <i>interpolated</i> title.</span></p>
<p>"<span [innerHTML]="title"></span>" is the <i>property bound</i> title.</p>
<p><img src="{{heroImageUrl}}"> is the <i>interpolated</i> image.</p>
<p><img [src]="heroImageUrl"> is the <i>property bound</i> image.</p>
来源:https://stackoverflow.com/questions/44759693/render-html-content-in-ionic-3-4