Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render string with html tags in Angular 4+? [duplicate]

People also ask

How do I render a string with HTML tag in angular 8?

To render a html string in angular, we can use the innerHTML property by binding a string to it. The innerHTML property sanitizes the html, so that your app is safe from the cross-site scripting attacks(XSS).

How do you render text in HTML?

<plaintext> HTML Tag The <plaintext> element was used to render HTML code as plain text. Since everything after the opening tag was rendered as plain text, there was no closing <plaintext> tag. This element is obsolete and should not be used. Instead, use the <code> or <pre> elements.

How do I display HTML inside an angular binding?

To add HTML that contains Angular-specific markup (property or value binding, components, directives, pipes, ...) it is required to add the dynamic module and compile components at runtime. This answer provides more details How can I use/create dynamic template to compile dynamic Component with Angular 2.0?

What is innerHTML in angular?

The innerHtml attribute is a standard HTML element attribute to which Angular 14 can bind with square brackets i.e [ & ] .


Use one way flow syntax property binding:

<div [innerHTML]="comment"></div>

From angular docs: "Angular recognizes the value as unsafe and automatically sanitizes it, which removes the <script> tag but keeps safe content such as the <b> element."