javascript - how can I communicate controllers in angularjs -
i have geographic data , want show them in map. used mapping applications first time developing map , angularjs. want show clicked data in map. have 2 controller named data , map. how can communicate them.
or there short way?
here 2 possibilities:
create service/factory on same module. inject both controllers. add $scope
$scope.sharedservice = myinjectedservice;
of both controllers. changes make properties exposed service visible both controllers.
depending on how designed controller hierarchy, either $scope.$emit (event travels parent scopes) or $scope.$broadcast (event travels down) event , add listener event receiving controller
$scope.$on("eventname", function(event, params){ //event handler code goes here });
Comments
Post a Comment