step by step

  1. create a script loading service with the script loading function
    @Injectable() export class ScriptLoadService {}
  2. import it as a provider to your app module
    providers: [ScriptLoadService]
  3. define it in your constructor in the component that uses the map
    constructor(private load: ScriptLoadService) {}