Sometimes, we want to append HTML to container element in Angular and TypeScript.
In this article, we’ll look at how to append HTML to container element in Angular and TypeScript.
How to append HTML to container element in Angular and TypeScript?
To append HTML to container element in Angular and TypeScript, we set the [innerHtml] attribute.
For instance, we write
this.htmlToAdd = '<div class="two">two</div>';
to set the htmlToAdd instance variable to a HTML string.
Then we render the content by writing
<div [innerHtml]="htmlToAdd"></div>
to set [innerHtml] to htmlToAdd to render the htmlToAdd string as raw HTML.
Conclusion
To append HTML to container element in Angular and TypeScript, we set the [innerHtml] attribute.