Skip to content

Instantly share code, notes, and snippets.

@paveltretyakovru
Created March 13, 2019 22:46
Show Gist options
  • Save paveltretyakovru/71a173259f8c05f104a8120ce8d53c75 to your computer and use it in GitHub Desktop.
Save paveltretyakovru/71a173259f8c05f104a8120ce8d53c75 to your computer and use it in GitHub Desktop.
Allow html properties when using angular [innerHtml] property on the tempate
import { BrowserModule, DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'my-app',
template: `
<div [innerHtml]="html"></div>
`,
})
export class App {
constructor(private sanitizer: DomSanitizer) {
this.html = sanitizer.bypassSecurityTrustHtml('<h1>DomSanitizer</h1><script>ourSafeCode()</script>');
}
}
/**
* @author Netanel Basal
* @site https://netbasal.com/angular-2-security-the-domsanitizer-service-2202c83bd90
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment