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.

1 Answer 1

5

You can bind to the innerHtml property.

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. It worked. Is this the only way to display? Any other alternatives you know?
I found a similar question.. You can have a look here stackoverflow.com/questions/31548311/angular-html-binding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.