Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!