I am trying to display a string as HTML and have it be able to execute like template code. Ultimately the string comes from the backend. Here is a Stack Blitz that shows my different attempts.
Can this be done in Angular (using 6)?
I am trying to display a string as HTML and have it be able to execute like template code. Ultimately the string comes from the backend. Here is a Stack Blitz that shows my different attempts.
Can this be done in Angular (using 6)?
Hello try bt using [innerHtml]
Edited
HTML
<div #divref [innerHTML]="html4"></div>
component
html4 = 'click <a><b>here</b></a>';
@ViewChild("divref", {read: ElementRef}) divref: ElementRef;
ngAfterViewInit() {
// child is set
this.divref.nativeElement.addEventListener('click', ()=>{
this.reset();
})
}
You need to sanitize your HTML using the DomSanitizer class before displaying the HTML. This is a built-in way to get around Angular's security against XSS.