1

I have some geographic data and I want to show them in a map. I used mapping applications but first time developing map and angularjs. I want to show clicked data in map. I have two controller named Data and Map. how can I communicate them.

Or is there another short way?

enter image description here

3
  • 1
    Use event broadcasting/emitting, or use a service Commented Jun 27, 2014 at 14:06
  • Use a service/factory. Here is a fiddle about it. Commented Jun 27, 2014 at 14:08
  • Googling looking for angular parent controller mixin take also a look at stackoverflow.com/questions/21427027/… Commented Jun 27, 2014 at 14:38

1 Answer 1

1

Here are 2 possibilities:

  1. Create a service/factory on the same module. Inject it into both controllers. Add it to $scope

    $scope.sharedService = myInjectedservice;
    

    of both controllers. Now any changes you make to the properties exposed by the service will be visible to both controllers.

  2. Depending on how you designed the controller hierarchy, either $scope.$emit (event travels up to parent scopes) or $scope.$broadcast (event travels down) an event and add a listener for that event to the receiving controller

    $scope.$on("eventName", function(event, params){
         //event handler code goes here
    });
    
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.