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