Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
Global method not being called unless I have a window.setTimeout of 1000 ms around the call

I have an index.html file and in it I have a script tag that's receiving a callback from google maps. If I remove the timeout, I get this error.

Uncaught TypeError TypeError: window.globalMethod is not a function

My 'globalMethod' is located in a directive being used on the page and I would assume maybe the directive's constructor isn't loaded, but I'm running the google maps script after <app-root></app-root> so you would think it would find window.globalMethod()?

I tried it with 100, but that doesn't seem to be long enough and still receive the error.

Here is index.html

<!doctype html>
<html lang="en">

<head>
  // left out other head tags for brevity
  <script>
    function initPlaces() {
      // won't run if I remove window.setTimeout
      window.setTimeout(() => {
        window.globalMethod();
      }, 1000);

    }
  </script>
</head>

<body>
  <app-root></app-root>
  <script src="https://maps.googleapis.com/maps/api/js?key=secret-key&libraries=places&callback=initPlaces" type="text/javascript"></script>
</body>

</html>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda