how to render a variable in angular that contains html without adding an extra container?

Viewed 120

The idea, that is not working:

<ng-container [innerHTML]="dataThatContainsHtml"></ng-container>

The working code, but it adds an extra html element, that I want to avoid:

<div class="avoid me" [innerHTML]="dataThatContainsHtml"></div>

Any solutions on this?

I tried to use pipes with DomSanitizer and print it like this:

{{ data | safeHTML }}

But the Angular renders this text SafeValue must use [property]=binding: ...

1 Answers

Alright, I've found a solution.

Code:

<div class="this div will not be rendered" [outerHTML]="dataThatContainsHtml"></div>

It will render dataThatContainsHtml without escaping HTML and will not render div

Related