Javascript 点击事件时AngularJS ngMap参数

Javascript 点击事件时AngularJS ngMap参数,javascript,angularjs,google-maps,Javascript,Angularjs,Google Maps,我正在尝试使用这个谷歌地图指令。 我想给每个标记添加一个点击事件,它调用控制器中的一个函数,通过标记的id。当我在控制台中打印出id时,我得到“hq{latLng:wf,ub:undefined,pixel:undefined,xa:undefined}”,这不是id。 我的HTML是 <map center="{{map.center.latitude}},{{map.center.longitude}}" zoom="{{map.zoom}}">

我正在尝试使用这个谷歌地图指令。 我想给每个标记添加一个点击事件,它调用控制器中的一个函数,通过标记的id。当我在控制台中打印出id时,我得到“hq{latLng:wf,ub:undefined,pixel:undefined,xa:undefined}”,这不是id。 我的HTML是

<map center="{{map.center.latitude}},{{map.center.longitude}}" zoom="{{map.zoom}}">

                    <marker ng-repeat="marker in markers" position="{{marker.latitude}}, {{marker.longitude}}" icon="{{marker.icon}}" id="{{marker.id}}" on-click="goAnchor(marker.id)"></marker>
                </map>

你应该在函数中使用

$scope.goAnchor = function (event) {
   console.log(event.target.attributes.id.value);
   gotoAnchor(event.target.attributes.id.value);
};
加价

<marker ng-repeat="marker in markers" position="{{marker.latitude}}, {{marker.longitude}}" icon="{{marker.icon}}" id="{{marker.id}}" on-click="goAnchor($event)"></marker>

“this”返回您单击的标记

$scope.goAnchor = function (event) {
 console.log(this.id);
 gotoAnchor(this.id);
};
HTML

<marker ng-repeat="marker in markers" position="{{marker.latitude}},{{marker.longitude}}" icon="{{marker.icon}}" id="{{marker.id}}" on-click="goAnchor($event)"></marker>

我使用下面的代码获取单击标记的纬度和经度

 <ng-map zoom="12" center="{{vm.geoCenterLoc}}" style="height:500px">
            <marker ng-repeat="p in vm.positions"
                    position="{{p.pos}}"
                    data="{{data[$index]}}"
                    on-click="myFunc($event)";
                    title="pos: {{p.pos}}"></marker>
   </ng-map>

这是我的想法,但文档显示点击。我尝试了ng click,但它甚至没有调用控制器,而on click却调用了。我从未在on click上看到
。但是我想要在控制器的
$scope
中传递函数的值,我们需要使用它的预定义指令。仍然没有运气。未捕获的TypeError:无法读取的属性“attributes”undefined@user1024941我的错。请检查我编辑的答案。我忘记在单击时在
中传递
$event
“让我们来吧”。如何访问此类回调函数中的scope变量?我认为它没有定义。
 <ng-map zoom="12" center="{{vm.geoCenterLoc}}" style="height:500px">
            <marker ng-repeat="p in vm.positions"
                    position="{{p.pos}}"
                    data="{{data[$index]}}"
                    on-click="myFunc($event)";
                    title="pos: {{p.pos}}"></marker>
   </ng-map>
$scope.myFunc = function (evt) {

            markerPosObj = {
                pos: [this.getPosition().lat(), this.getPosition().lng()]
            };
            markerPos = [];
            markerPos.push(markerPosObj);
            console.log('this marker', markerPos);
        }