Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google map Key move from index.html #94

Open
manojkumarbehera opened this issue Jun 16, 2021 · 1 comment
Open

google map Key move from index.html #94

manojkumarbehera opened this issue Jun 16, 2021 · 1 comment

Comments

@manojkumarbehera
Copy link

keeping map key in index.html not a good idea in live environment.
Is there way can move the key from index.html to app.module.ts or environment.ts

@sscholle
Copy link

you may want to use an npm package such as 'load-script2' and implement a dynamic loader such as this:

import loadScript from 'load-script2';
let scriptPromise: Promise<any> | null = null;
export const scriptLoader = (scriptSrc: string, attrs?: object, parentNode?: HTMLElement, apiExists?: (any) => boolean): Promise<any> => {
  // if(!scriptPromise)
  scriptPromise = new Promise((resolve, reject) => {
    if (apiExists && apiExists(window as any)) {
      console.log('scriptLoader:apiExists', scriptSrc);
      resolve((window as any));
    } else {
      console.log('scriptLoader:loadScript', scriptSrc);
      loadScript(scriptSrc, attrs, parentNode)
      .then(() => {
        resolve((window as any));
      })
      .catch((err) => {
        reject(err);
      });
    }
  });
  return scriptPromise;
};

you can pass in your Google maps api url (and the key can be stored basically any way you like):
example:

scriptLoader(
      "YOUR SCRIPT HERE",
    ).then((win) => {
      // script loaded
    }).catch(e => {
      // something broke
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants