Reputation: 6875
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?
Upvotes: 1
Views: 69
Reputation: 471
Here are 2 possibilities:
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.
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
});
Upvotes: 1