1

I am banging my head with this. My controller structure is appController at the top, then a mapController. all other controllers are nested and are parallel of each other. they are being instantiated with the ui-router ui-view state change.

In my map controller I have this inside a function

$scope.$broadcast('selectedIdsForExport', selectedIds);

this works. the $on function is inside a chartController that has just been instantiated with a state change.

$scope.$on('selectedIdsForExport', function (event, selectedIds) {

this is being hit from the broadcast. but it does not enter the function.it skips over it.this is where i am lost. I do have this $on function inside a $watch function, I thought that could be a issue but if it was a issue the $on function would not be hit? Am I wrong about that?

how can i trouble shoot this?

note that inside my mapController I have 2 functions that both have the same $broadcast function. This should not be a issue? also I two chartControllers that have the same $on function. But if that was a issue the breakpoint would not catch on the $on function that I am trying to enter. is that correct? here is a couple of screenshots that might help. on my page load/refresh this is the pattern. this works correctly pic1

when I click on the tab to switch charts, this is the pattern. pic2

this is where it skips over the $on function

texas697
  • 5,609
  • 16
  • 65
  • 131
  • Can you post a fiddle or a plunk illustrating the problem? I would also remove the $on from inside the $watch just from a pure code quality standpoint. – sma Aug 21 '15 at 18:20
  • 1
    Why would you include the listener in a $watcher ? – malifa Aug 21 '15 at 18:20
  • What he^ said. Every time your value changes you are generating the same listener over and over again. Memory leaks. – Rorschach120 Aug 21 '15 at 18:23
  • Why not include the relevant code and controller hierarchy instead of trying to explain in words? Why do we need to tease out the true meaning of apparently contradictory statements of "controllers are nested and are parallel", or "hit from the broadcast. but it does not enter the function.it skips over it"? – New Dev Aug 21 '15 at 18:24
  • I was handed this project. its not setup the best way. but i need to get it going as is. – texas697 Aug 21 '15 at 18:31

1 Answers1

2

I think this is the issue of the parent and child priority on calling them $on and $broadcast.

please read the following stackoverflow question.

Working with $scope.$emit and .$on

Community
  • 1
  • 1
Tabish
  • 1,592
  • 16
  • 13