0

I think this is a problem in angularjs and not specifically in wrong usage of a google map directive.

I have a map markup using a directive like so.

<map>
   <marker on-click="setSelected(e,item)"></marker>
</map>

and in my controller

$scope.selectedItem = {};
$scope.setSelected = function(e,item){
 $scope.selectedItem = item;
 // console.log($scope.selectedItem)
}

When I log the selectedItem, I am getting the expected result, but when I try to use the variable in a template, it just don't work at all like so

<p>{{selectedItem}}</p>

What do you think is the mistake here.

1
  • For more clarification you could post a working JSFiddle. Commented May 13, 2014 at 20:36

1 Answer 1

3

Wrap everything within the function setSelected around an AngularJS $apply like so:

$scope.setSelected = function(e,item){
    $scope.$apply(function () {
        $scope.selectedItem = item;
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.