0

Here's a snippet of an angular google map:

<ui-gmap-markers models='theWinner' events="map.markerEvents" coords='"coordinates"'>
    <ui-gmap-windows show="show">
        <div ng-non-bindable>{{ coordinates }}</div>
        <div ng-click="$root.derp(coordinates)">navigate</div>
    </ui-gmap-windows>
</ui-gmap-markers>         

I need derp() to be in $root in order to use it from within the angular google map. I also need to pass the coordinates which are defined in regular ol' $scope. As-is, the above code does not work. {{ coordinates }} are available to the template, but not they are not passed to $root.derp().

What's the cleanest way to fix this problem? Thanks!

Edit: It occurs to me that I could explicitly create a copy of the coordinates in a $root variable, like so:

$scope.$root.coordinates = coordinates;

Kind of messy, having two copies of the same variable, but it works. Is there a better way? I don't like abusing $root more than I have to.

crowhill
  • 2,398
  • 3
  • 26
  • 55

1 Answers1

0

Why exactly do you need derp() to be in $root? If its for the sake of sharing data between controllers you should use a factory/service. If there is no way around as you already answered yourself the correct way is to "copy"/set the value. A similar question

Community
  • 1
  • 1
SeRu
  • 314
  • 1
  • 6