Categories
Angular Answers

How to append HTML to container element in Angular and TypeScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *