angularjs - ng-map: How can I get the Marker object when I click it? -
i using pretty cool ng-map library angular, , want know how access underlying marker object referenced ng-map marker directive
so, have markup:
<div id="map-search" data-tap-disabled="true">   <map zoom="15" disable-default-u-i="true">     <marker ng-repeat=" pos in positions" position="{{pos.latitude}}, {{pos.longitude}}" id="{{pos.index}}" on-click="pinclicked()">     </marker>   </map> </div> i haven't found straight-forward way of accessing google maps marker object during on-click event in case; controller:
  app.controller('mapsearchcontroller', function($scope) {        $scope.$on('mapinitialized', function(event, map) {         $scope.map = map;         //assume existence of array of markers         $scope.positions = generatepinpositionsarray();       });        $scope.pinclicked = function(event, marker) {         console.log('clicked pin!');         //how can marker object (the 1 clicked) here?         console.log('the marker ->', marker); //prints undefined       };   }); thanks in advance,
you need create array of markers ! that's (in opinion) way. see here
update: plunkr works you?
the idea pass marker on event on-click="pinclicked(this)". , can catch later on controller: $scope.pinclicked = function(events, marker) {...}
Comments
Post a Comment