如何在angularjs中调用initmap方法,因为。当我点击刷新按钮时工作正常,当我点击刷新按钮时工作正常,当我更改点击,点击地图标签地图显示如下图片
this。$ window.initMap如何在angularjs中调用此方法
this.$window.initMap = function () { } //this method map was show properly, but i am using tap , this code does not work
<li><a ng-click="initMap()" href="#map" data-toggle="tab">Map</a></li>
答案 0 :(得分:1)
然后在你的调用中删除initMap的回调
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"
async defer></script>
然后你的电话应该有效
<li><a ng-click="initMap()" href="#map" data-toggle="tab">Map</a></li>
然后检查创建
<script>
var map;
var mapCreated = false;
function initMap() {
if (mapCreated == false) {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
mapCreated = true;
}
}
</script>