I am working on an application where i am getting responses in html format from a server. I am using the DomSanitizer\'s bypassSecurityTrustHtml and adding the sanitized htm
This isn't possible with [innerHTML]="..."
at all.
You can compile components at runtime to get components and directives for dynamic HTML.
See How can I use/create dynamic template to compile dynamic Component with Angular 2.0? for more details.
Maybe try using Pipe, like this:
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: 'safeHTML' })
export class SafeHtml implements PipeTransform {
constructor(private sanitizer: DomSanitizer) { }
transform(html: string) {
return this.sanitizer.bypassSecurityTrustHtml(html)
}
}
and than
[innerHtml]="htmlExample | safeHTML"