如何在AngularJS中使用$ Watch()函数进行Google Map API点击事件?
我想捕获单击事件时,当您在Google地图上单击标记时发生,然后执行一些代码。我已经尝试过,但似乎没有用。
$scope.$watch('click', function(newVal, oldVal) {
alert("Marker was clicked");
});
有什么想法吗?
I want to catch the click event that happens when you click on a marker on a google map, and then execute some code. I've tried this, but it doesn't seem to be working.
$scope.$watch('click', function(newVal, oldVal) {
alert("Marker was clicked");
});
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google Maps以iframe显示了地图,并且您无法使用iframe捕获单击。我使用 ngmap 用于我的gangularjs应用中的地图显示,而html结构最终看起来像这样:
看到
点击
在其中?在这里,您可以点击并在代码中执行一些操作。我的JS看起来像这样:
没有尝试解释所有内容,您可以看到(使用精美的NGMAP软件包)可以捕获标记上的单击。
Google maps displays the map in an iframe, and you can't capture clicks like that with an iframe. I use NgMap for map displays in my angularJS app, and the HTML structure ends up looking like this:
See that
on-click
in there? That is where you can get the click and do something in your code.My JS looks something like this:
Without trying to explain everything, you can see that (using the wonderful NgMap package) you can capture the click on the marker.