Skip to content

Instantly share code, notes, and snippets.

@koswarabilly
Last active June 19, 2020 03:03
Show Gist options
  • Save koswarabilly/0d0f4a79cacc384a118d66584d91e1f3 to your computer and use it in GitHub Desktop.
Save koswarabilly/0d0f4a79cacc384a118d66584d91e1f3 to your computer and use it in GitHub Desktop.
Angular load compiled project
<div id="htmlcontainer" [innerHTML]="myTemplate"></div>
this.http.get('http://url.com', {
headers: new HttpHeaders({
// "Access-Control-Allow-Origin": "*"
}),
responseType: "text"
})
.subscribe(
data => {
let html = JSON.parse(JSON.stringify(data))
html = html.replace(`href="styles.2f473f68ee5c98560db8.css"`, `href="http://url.com/styles.2f473f68ee5c98560db8.css"`)
// html = html.replace(`src="runtime.e1705607d9d4ff86bc3f.js"`, `src="http://url.com/runtime.e1705607d9d4ff86bc3f.js"`)
// html = html.replace(`src="polyfills.50bb19084f93310865a0.js"`, `src="http://url.com/polyfills.50bb19084f93310865a0.js"`)
// html = html.replace(`src="scripts.c0e6b569f43581c2f5b5.js"`, `src="http://url.com/scripts.c0e6b569f43581c2f5b5.js"`)
// html = html.replace(`src="main.60b15a921123dfca983b.js"`, `src="http://url.com/main.60b15a921123dfca983b.js"`)
// html = html.replace(`src="runtime.e1705607d9d4ff86bc3f.js"`, `href="http://url.com/runtime.e1705607d9d4ff86bc3f.js"`)
console.log(this._sanitizer.bypassSecurityTrustHtml(html))
this.myTemplate = this._sanitizer.bypassSecurityTrustHtml(html + "<div><div m-root></div><div>")
let body = <HTMLDivElement> document.body
let scripts_1 = document.createElement("script"), scripts_2 = document.createElement("script"), scripts_3 = document.createElement("script"), scripts_4 = document.createElement("script");
this.http.get("http://url.com/runtime.e1705607d9d4ff86bc3f.js", {
headers: new HttpHeaders({
// "Access-Control-Allow-Origin": "*"
}),
responseType: "text"
}).subscribe(sc1 => {
scripts_1.innerText = sc1.replace(`c.p+""`, `c.p+"http://url.com/"`)
body.appendChild(scripts_1)
})
// scripts_1.src = "http://url.com/runtime.e1705607d9d4ff86bc3f.js";
// scripts_2.src = "http://url.com/polyfills.50bb19084f93310865a0.js";
scripts_3.src = "http://url.com/scripts.c0e6b569f43581c2f5b5.js";
this.http.get("http://url.com/main.60b15a921123dfca983b.js", {
headers: new HttpHeaders({
// "Access-Control-Allow-Origin": "*"
}),
responseType: "text"
}).subscribe(sc4 => {
scripts_4.innerText = sc4.replace("body[m-root]", "div[m-root]")
body.appendChild(scripts_4)
})
// scripts_4 = "http://url.com/main.60b15a921123dfca983b.js";
body.appendChild(scripts_1)
body.appendChild(scripts_2)
body.appendChild(scripts_3)
body.appendChild(scripts_4)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment