'Use Angular 9 DomSanitizer to run inline scripts with innerHtml
Have a file containing html, css and script.
<style>
h1{
color: darkgreen;
}
</style>
<H1 id="header">Title</H1>
<script>
alert("script executed");
</script>
I am using angular Domsanatizer, the html and css works, but the script is not executed.
In Component .ts file
this.safeContentFromFile = this.sanatizer.bypassSecurityTrustHtml(this.contentFromFile);
Component template
<div *ngIf="contentReady" [innerHtml]="safeContentFromFile" id="content-window"></div>
Any suggestion on how to get the script to work with this.
Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
