How to get angular2 [innerHtml] to work [duplicate]
Angular uses {{property}}
for interpolation of values. That is the way that you would display plain text in your div
, like so
Solution 1:
<div class="blog-post">{{testhtml}}</div>
But that will write out text, not HTML.
For HTML, you will need to bind to the property
Solution 2:
<div class="blog-post" [innerHtml]="testhtml"></div>
Note I moved the [innerHtml]
to inside the div
tag.
Leaving out the square brackets would bind to the attribute, so you would need to interpolate again
Solution 3:
<div class="blog-post" innerHtml="{{testhtml}}"></div>
The property binding (Solution 2) is the preferred method.
You have to add attributes inside the tag like this.
<div class="blog-post" [innerHtml]="testhtml"></div>