代码之家  ›  专栏  ›  技术社区  ›  chuckd

除非有窗口,否则不会调用全局方法。设置通话期间的超时时间为1000毫秒

  •  0
  • chuckd  · 技术社区  · 4 年前

    我有索引。html文件,其中有一个脚本标记,它正在接收来自google maps的回调。如果我删除超时,就会出现这个错误。

    未捕获类型错误类型错误:窗口。globalMethod不是一个函数

    我的“globalMethod”位于页面上使用的一个指令中,我假设该指令的构造函数可能没有加载,但我会在之后运行google maps脚本 <app-root></app-root> 所以你认为它会发现 window.globalMethod() ?

    我尝试了100次,但似乎时间不够长,仍然收到了错误。

    这里是索引。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>
    0 回复  |  直到 4 年前