-
Notifications
You must be signed in to change notification settings - Fork 1
Adding HTML
einarhuseby edited this page Feb 21, 2018
·
3 revisions
Adding HTML requires DomSanitizer or using the safe pipe.
DomSanitizer:
// TS
import { DomSanitizer } from '@angular/platform-browser';
export class {
image: string;
constructor(public domSanitizer: DomSanitizer) { }
public setImage() {
api.getImage(id).subscribe(
data =>
this.image = 'data:' + data.content_type + ';base64,' + data.file;
....
}
// html:
<img [src]="domSanitizer.bypassSecurityTrustUrl(image)">
Safe pipe:
<p [innerHTML]="htmltext | newlines | safe: 'html'"></p>