Created
March 13, 2019 22:46
-
-
Save paveltretyakovru/71a173259f8c05f104a8120ce8d53c75 to your computer and use it in GitHub Desktop.
Allow html properties when using angular [innerHtml] property on the tempate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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