javascript 角度 $scope.$on 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32146868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
angular $scope.$on is not working
提问by texas697
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.
我正在用这个敲我的头。我的控制器结构是顶部的 appController,然后是一个 mapController。所有其他控制器都是嵌套的并且彼此平行。它们正在通过 ui-router ui-view 状态更改进行实例化。
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.
这有效。$on 函数位于刚刚通过状态更改实例化的 chartController 中。
$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?
这是从广播中被击中的。但它没有进入函数。它跳过它。这是我迷路的地方。我确实在 $watch 函数中有这个 $on 函数,我认为这可能是一个问题,但如果它是一个问题,$on 函数不会被击中?我错了吗?
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
请注意,在我的 mapController 中,我有 2 个函数,它们都具有相同的 $broadcast 函数。这应该不是问题吧?我还有两个具有相同 $on 函数的图表控制器。但是,如果这是一个问题,断点将不会捕捉到我试图输入的 $on 函数。那是对的吗?这是一些可能有帮助的屏幕截图。在我的页面加载/刷新这是模式。这工作正常
when I click on the tab to switch charts, this is the pattern.
this is where it skips over the $on function
这是它跳过 $on 函数的地方
回答by Tabish
I think this is the issue of the parent and child priority on calling them $on and $broadcast.
我认为这是父母和孩子优先调用他们 $on 和 $broadcast 的问题。
please read the following stackoverflow question.
请阅读以下 stackoverflow 问题。