Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 - render template from string variable holding template

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.

like image 523
Vinni Avatar asked Sep 19 '25 19:09

Vinni


1 Answers

You can bind to the innerHtml property.

  <div [innerHtml]="stringTemplate"></div>
like image 147
Yoni Affuta Avatar answered Sep 21 '25 11:09

Yoni Affuta