I have this module which componentize the external library together with additional logic without adding the tag directly into the index.html:
Yet another option would be to utilize scriptjs package for that matter which
allows you to load script resources on-demand from any URL
Example
Install the package:
npm i scriptjs
and type definitions for scriptjs:
npm install --save @types/scriptjs
Then import $script.get()
method:
import { get } from 'scriptjs';
and finally load script resource, in our case Google Maps library:
export class AppComponent implements OnInit {
ngOnInit() {
get("https://maps.googleapis.com/maps/api/js?key=", () => {
//Google Maps library has been loaded...
});
}
}
Demo