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?

enter image description here

here 2 possibilities:

  1. 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.

  2. 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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -