I have load the HTML page by http.get() method, and i add content this page to div tag.
getRequestToAssignPage (param: string) : an
In your template, you can set up something like:
In the corresponding component, you can load your HTML into your template, build up an array of script tags, and eval each one:
@ViewChild('htmlContainer') container;
ngOnInit() {
this.http.get('html-file.html').subscribe((res: Response) => {
this.trustedHTML = this.sanitizer.bypassSecurityTrustHtml(res.text());
setTimeout(() => { //wait for DOM rendering
let scripts = this.container.nativeElement.getElementsByTagName('script');
for (let script of scripts){
eval(script.text)
}
})
});
I hate that I have to resort to using setTimeout and eval for something so seemingly simple, but it works.
...but not for