谷歌地图加载回调 - 角度



我正在努力将Google Maps JS API添加到我的Angular项目中。

index.htm我有:

 <script src="https://maps.googleapis.com/maps/api/js?key=API_KEY"
        async defer></script>

在我的组件中,如何知道maps api已满载且可用?

为了清楚起见,例如,在 Google 图表 API 中,我们可以调用:

google.charts.setOnLoadCallback();

以启动其他功能。

您可以尝试在脚本标记中使用 onload 事件:

示例(https://codepen.io/larryjoelane/pen/BJmOxB?editors=1112(:

<script>
  function jsFileLoaded() {
    console.log('file loaded!');
  }
</script>
<script src ="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js" onload="jsFileLoaded()" async defer></script>

最新更新