I have this module which componentize the external library together with additional logic without adding the tag directly into the index.html:
Hi you can use Renderer2 and elementRef with just a few lines of code:
constructor(private readonly elementRef: ElementRef,
private renderer: Renderer2) {
}
ngOnInit() {
const script = this.renderer.createElement('script');
script.src = 'http://iknow.com/this/does/not/work/either/file.js';
script.onload = () => {
console.log('script loaded');
initFile();
};
this.renderer.appendChild(this.elementRef.nativeElement, script);
}
the onload function can be used to call the script functions after the script is loaded, this is very useful if you have to do the calls in the ngOnInit()