Skip to main content

First create Ana Pipe.

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe({
name: 'sanitizer',
})

export class SanitizerUrlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}

transform(value: string, args: any = 'SafeURL'): SafeUrl | SafeHtml {
    if (args == 'SafeHtml') {
        return this.sanitizer.bypassSecurityTrustHtml(value);
    } 
  }
}

After UseThen, use the pipe in your HTML template like this.

<div [innerHtml]="data | sanitizer : 'SafeHtml'"></div>

First create An Pipe

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe({
name: 'sanitizer',
})

export class SanitizerUrlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}

transform(value: string, args: any = 'SafeURL'): SafeUrl | SafeHtml {
    if (args == 'SafeHtml') {
        return this.sanitizer.bypassSecurityTrustHtml(value);
    } 
  }
}

After Use this

<div [innerHtml]="data | sanitizer : 'SafeHtml'"></div>

First create a Pipe.

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe({
name: 'sanitizer',
})

export class SanitizerUrlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}

transform(value: string, args: any = 'SafeURL'): SafeUrl | SafeHtml {
    if (args == 'SafeHtml') {
        return this.sanitizer.bypassSecurityTrustHtml(value);
    } 
  }
}

Then, use the pipe in your HTML template like this.

<div [innerHtml]="data | sanitizer : 'SafeHtml'"></div>
Source Link
Alex
  • 11
  • 2

First create An Pipe

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';

@Pipe({
name: 'sanitizer',
})

export class SanitizerUrlPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}

transform(value: string, args: any = 'SafeURL'): SafeUrl | SafeHtml {
    if (args == 'SafeHtml') {
        return this.sanitizer.bypassSecurityTrustHtml(value);
    } 
  }
}

After Use this

<div [innerHtml]="data | sanitizer : 'SafeHtml'"></div>