npm i ngx-sanitizer
- Import
NgxSanitizerModule
into your module(s).
This library provides a set of simple yet useful pipes:
SafeUrlPipe
SafeHtmlPipe
SafeStylePipe
SafeScriptPipe
SafeResourceUrlPipe
that can be used to say Angular we trust the data we provide, e.g.:
@Component({
template: `<p [innerHtml]="someUntrustedHtml | safeHtml"></p>`,
})
export class SomeComponent {
someUntrustedHtml = '<strong onclick="alert(\'and clickable\');">I am Strong!</strong>';
}