Skip to content Skip to sidebar Skip to footer

How To Render A Raw Html On Angular

I've tried to render a raw HTML using innerHTML, as bellow: This HTML has style in line, but it does n

Solution 1:

Potentially, you need a SafePipe for your html as your browser does not trust injected html code:

import { Pipe, PipeTransform } from'@angular/core';

@Pipe({ name: 'safePipe'})

exportclasssafePipeimplementsPipeTransform  {

constructor(protected sanitizer: DomSanitizer):{}

  transform(value) {
    returnthis.sanitizer.bypassSecurityTrustHtml(value);
  }
}

usage in HTML:

<span [innerHtml]="potentiallyNotSafeHtmlCode | safePipe"></span>

Post a Comment for "How To Render A Raw Html On Angular"