谷歌地图在角度指令中不起作用
16lz
2021-01-22
GoogleMapsAPI implementation doesn't publish the map in the directory template. Here is the markup and code
GoogleMapsAPI实现不会在目录模板中发布映射。这是标记和代码
<gmap-locator></gmap-locator>
.
app.directive('gmapLocator', function () {
var link = function (scope, element, attrs) {
var map, mapOptions, markers;
var lat = scope.mapParameters.initialSettings.Lat;
var lng = scope.mapParameters.initialSettings.Lng;
mapOptions = {
mapTypeId : google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(lat, lng),
zoom: scope.mapParameters.initialSettings.zoom
};
function initMap() {
if (map === void 0) {
map = new google.maps.Map(element[0], mapOptions);
}
}
initMap();
}
return {
restrict: 'EA',
scope: {
mapParameters: '='
},
template: "<div id='gomap' style='height: 400px;width:300px'></div>",
controller: controller,
link: link
}
return {
restrict: 'EA',
template: '<div id="gomap" style="width: 450px;height:400px;"></div>',
link: link
};
});
Google Maps library doesn't detect the target div and publish the map..
Google地图库未检测到目标div并发布地图。
1 个解决方案
#1
this is happening because <div id="gomap"..
is published a child element to the directive element <gmap-locator map-parameters="mapParameters"></gmap-locator>
So the GoogleMaps initialization code in the initmap function should be changed to
这是因为
所以initmap函数中的GoogleMaps初始化代码应该改为更多相关文章
- Aptana Studio 3 IDE中有运行JavaScript代码的方法吗?
- 如何在JavaScript中编写适当的OOP代码?
- 高性能JavaScript代码高亮插件
- js“DOM事件”之鼠标事件、js的测试方法、js代码的放置位置
- 使用Node.js初始化和配置AWS
- JavaScript 最佳实践:帮你提升代码质量
- 关于JavaScript变量声明及其初始化的问题
- 利用javascript实现遍历xml文件的代码实例
- javascript 的MD5代码备份,跟java互通