GoogleMap 在我的 Angular 项目(WebStorm IDE)中不可见!!
我试过使用回调函数!! GoogleMap 仍然不可见!! I get this Error in Console
index.html
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAANu_sjcxDH04GZHg187EGg6csTeiX-jw&callback=initMap"
defer></script>
MapCtrl.js
.controller('MapCtrl',function ($scope, $window) {
$window.initMap = function () {
var map=new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
});
Mymap.html
<div id="map" ng-controller="MapCtrl"></div>
最佳答案
我曾经遇到过同样的问题。我通过从 src url 的末尾删除 '&callback=initMap' 来解决它。在你的情况下;
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAANu_sjcxDH04GZHg187EGg6csTeiX-jw"
defer></script>
代替
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAANu_sjcxDH04GZHg187EGg6csTeiX-jw&callback=initMap"
defer></script>
关于javascript - initMap 不是函数 : Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40588011/