Google地图属性的Angular指令已丢失

时间:2015-10-20 09:56:33

标签: javascript angularjs google-maps

我正在尝试创建一个简单的指令来显示存储在mongo文档中的位置的谷歌地图。
我将坐标作为属性传递但是当我将它们放入attrs参数时在前看不见。

<div id="map" lat="{{ location.latitude }}" lng="{{ location.logitude }}" google-map></div>

指令:

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

  ...

那么,问题是,为什么我无法访问attrs属性?我怎么能得到它们? 感谢。

0 个答案:

没有答案