(angularjs - 谷歌 - 地图)内的标记NG-点击 [英] (angularjs-google-maps) ng-click inside marker

查看:175
本文介绍了(angularjs - 谷歌 - 地图)内的标记NG-点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这问题是关于 angularjs - 谷歌 - 地图 https://github.com/allenhwkim/angularjs-google-maps

在标记

有没有使用方式NG单击设置这样的变量? (1的值是用于测试目的硬codeD)。目前,点击标记似乎不触发NG-点击。

 <标记NG重复=比如在common.instances
 位置=[{{instance.lat}},{{instance.lng}}]
 NG-点击=common.selectedinstance = 1>
< /标记>


解决方案

从他们的文件, https://developers.google.com/maps/documentation/javascript/events


  

用户事件(如点击鼠标事件)是从DOM传播
  到谷歌地图API。这些事件的单独的不同
  标准DOM事件。


据我了解,只有谷歌地图事件可以被应用到谷歌地图对象,包括标记,形状等。

这是个坏消息。

好消息是你仍然可以使用上点击事件来处理 $范围变量和事件。没有太大的区别,只要你使用函数此事件。

我会继续调查是否有解决方法,这样我们就可以使用AngularJS事件成(即。ngMouseenger,ngMouseleave。ngMouseup,ngClick等

在使用单击一个工作的例子是plunkr,以满足您的要求。

http://plnkr.co/edit/6qvS0vUYkqVHZ3t6qmn2?p=$p$ PVIEW

这是脚本的一部分

  $ scope.myVar = 1;
  $ scope.changeMyVar =函数(事件){
    $ scope.myVar + = 1;
    $ $范围适用于()。
  }

这是HTML的一部分

 <地图缩放=11中心=[40.74,-74.18]>
    <标记NG重复=p在岗位
      位置={{P}}称号={{p.toString()}}
      上点击=changeMyVar()>
    < /标记>
  < /图>
  myVar的:{{myVar的}}点击一个标记,以增加myVar的

要了解更多关于angularjs - 谷歌 - 地图活动,请看一看的有关事件的例子

This question is about angularjs-google-maps, https://github.com/allenhwkim/angularjs-google-maps

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>

解决方案

From their document, https://developers.google.com/maps/documentation/javascript/events,

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.

That was the bad news.

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.

I will keep investigating if there is work-around, so that we can use AngularJS Event into(i.e. ngMouseenger, ngMouseleave. ngMouseup, ngClick, etc

A working example using on-click is at plunkr to satisfy your requirement.

http://plnkr.co/edit/6qvS0vUYkqVHZ3t6qmn2?p=preview

This is script part

  $scope.myVar = 1;
  $scope.changeMyVar = function(event) {
    $scope.myVar+=1;
    $scope.$apply();
  }

This is html part

  <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

To know more about angularjs-google-maps events, please take a look at the example about event

这篇关于(angularjs - 谷歌 - 地图)内的标记NG-点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆