4

How to render a html using a string variable (holding template) - Angular4.

sample.component.ts

let stringTemplate = "<div><p>I should be rendered as a HTML<br></p></div>";

sample.component.html should be rendered based on elements in variable stringTemplate

NOTE: stringTemplate is not static. Will be getting its data from server.

Vinni
  • 569
  • 1
  • 8
  • 18

1 Answers1

5

You can bind to the innerHtml property.

  <div [innerHtml]="stringTemplate"></div>
Yoni Affuta
  • 284
  • 1
  • 5
  • 1
    Thanks a lot. It worked. Is this the only way to display? Any other alternatives you know? – Vinni Nov 09 '17 at 06:10
  • I found a similar question.. You can have a look here https://stackoverflow.com/questions/31548311/angular-html-binding – Yoni Affuta Nov 09 '17 at 07:09