Javascript google Maps属性丢失的Angular指令
我试图创建一个简单的指令来显示存储在mongo文档中的位置的google地图。Javascript google Maps属性丢失的Angular指令,javascript,angularjs,google-maps,Javascript,Angularjs,Google Maps,我试图创建一个简单的指令来显示存储在mongo文档中的位置的google地图。我将坐标作为属性传递,但当我将它们放入attrs参数时,它们将消失。 <div id="map" lat="{{ location.latitude }}" lng="{{ location.logitude }}" google-map></div> 因此,问题是,为什么我不能访问attrs属性?我怎样才能得到它们? 谢谢。您能将示例代码放入JSFIDLE吗?这会帮助我回答你的问题。有时,L
我将坐标作为属性传递,但当我将它们放入
attrs
参数时,它们将消失。<div id="map" lat="{{ location.latitude }}" lng="{{ location.logitude }}" google-map></div>
因此,问题是,为什么我不能访问attrs
属性?我怎样才能得到它们?
谢谢。您能将示例代码放入JSFIDLE吗?这会帮助我回答你的问题。有时,Lat和lng值存储为函数。尝试console.log(attrs.lat())感谢您的回复。我最终解决了这个问题,使用谷歌地图的角度依赖关系,而不是制定自己的指令。
app.directive('googleMap', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
console.log(attrs); // Will show lat and lng properties with their corresponding values
console.log(attrs.lat); // Will show nothing. (!?)
var options = {
center: new google.maps.LatLng(attrs.lat, attrs.lng), // It will systematically center to the coordinates 0,0
...