(angularjs-google-maps) ng-click 内部标记 [英] (angularjs-google-maps) ng-click inside marker
问题描述
这个问题是关于angularjs-google-maps
,https:///github.com/allenhwkim/angularjs-google-maps
有没有办法在标记上使用 ng-click 来设置这样的变量?(值 1 是硬编码用于测试目的).当前单击标记似乎不会触发 ng-click.
Is there a way to use ng-click on a marker to set a variable like this? (the value of 1 is hard-coded for testing purposes). Clicking the marker currently does not seem to trigger the ng-click.
<marker ng-repeat="instance in common.instances"
position="[{{instance.lat}},{{instance.lng}}]"
ng-click="common.selectedinstance = 1">
</marker>
推荐答案
来自他们的文档,https://developers.google.com/maps/documentation/javascript/events、
用户事件(例如单击"鼠标事件)从 DOM 传播到谷歌地图 API.这些事件与独立和不同标准 DOM 事件.
User events (such as "click" mouse events) are propagated from the DOM to the Google Maps API. These events are separate and distinct from standard DOM events.
据我所知,只有谷歌地图事件可以应用于谷歌地图对象,包括标记、形状等
As far as I understand, only google maps event can be applied to google maps objects including markers, shapes, etc.
那是坏消息.
好消息是您仍然可以使用 on-click
事件来操作 $scope
变量和事件.只要为这个事件使用一个函数就没有太大区别.
Good news is you still can use on-click
event to manipulate $scope
variables and events. There is not much difference as long as you use a function for this event.
我会继续调查是否有变通办法,以便我们可以使用 AngularJS 事件进入(即 ngMouseenger、ngMouseleave、ngMouseup、ngClick 等)
I will keep investigating if there is work-around, so that we can use AngularJS Event into(i.e. ngMouseenger, ngMouseleave. ngMouseup, ngClick, etc
plunkr 的一个使用点击的工作示例可以满足您的要求.
A working example using on-click is at plunkr to satisfy your requirement.
http://plnkr.co/edit/6qvS0vUYkqVHZ3t6qmn2?p=preview
这是脚本部分
$scope.myVar = 1;
$scope.changeMyVar = function(event) {
$scope.myVar+=1;
$scope.$apply();
}
这是html部分
<map zoom="11" center="[40.74, -74.18]">
<marker ng-repeat="p in positions"
position="{{p}}" title="{{p.toString()}}"
on-click="changeMyVar()">
</marker>
</map>
myVar : {{myVar}} Click a marker to increase myVar
要了解有关 angularjs-google-maps 事件的更多信息,请查看 事件示例
To know more about angularjs-google-maps events, please take a look at the example about event
这篇关于(angularjs-google-maps) ng-click 内部标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!