Adding HTML - luftsport/nlf-client GitHub Wiki

Adding HTML requires DomSanitizer or using the safe pipe.

DomSanitizer:

// 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>

Safe pipe:

import { SafePipe } from './../../pipes/safe.pipe';

Then use in templates as:

 <p [innerHTML]="htmltext | safe: 'html'"></p>
⚠️ **GitHub.com Fallback** ⚠️