Google Maps Onload Callback -Angular

时间:2018-01-07 05:20:04

标签: javascript angular google-maps google-maps-api-3

我正在努力将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 Charts API中,我们可以调用:

google.charts.setOnLoadCallback();

启动其他功能。

1 个答案:

答案 0 :(得分:0)

您可以尝试在脚本标记中使用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>