Last active
October 27, 2024 21:43
-
-
Save Mustafa-Omran/485d5cbd9eb6a151638882cb754811b6 to your computer and use it in GitHub Desktop.
Dynamic Script In Angular
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
/** | |
* Append script to HTML page | |
* | |
* | |
* @param src {string} | |
*/ | |
createScript(src: string): void { | |
const configsScript = document.createElement('script'); | |
configsScript.type = 'text/javascript'; | |
configsScript.innerText = ` | |
var data = { | |
// script data here | |
} | |
`; | |
this.renderer.appendChild(document.body, configsScript); | |
const script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = src; | |
this.renderer.appendChild(document.body, script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment