Vinni
Vinni

Reputation: 589

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.

Upvotes: 4

Views: 3501

Answers (1)

Yoni Affuta
Yoni Affuta

Reputation: 284

You can bind to the innerHtml property.

  <div [innerHtml]="stringTemplate"></div>

Upvotes: 5

Related Questions