我有一个弹出式的控制器:
I have a popup controller:
@PopupController = ["$scope", ($scope) ->
$scope.isActive = false
$scope.open = ->
$scope.isActive = true
]
和老师控制器:
@TeachersController = ["$scope", "Teacher", ($scope, Teacher) ->
$scope.teachers = Teacher.query()
$scope.showTeacher = ->
# somehow call PopupController.open()
]
如何调 PopupController.open()
从 TeachersController
?
或者,也许我这样做是错误和角度有一些更好的方法来实现它?
Or maybe I'm doing it wrong and Angular has some better ways to implement it?
您可以使用的 $广播(向下子作用域)或$排放(向上范围层次),以一个控制器发送一个事件的形式向其他。
You may use $broadcast (downward to child scopes) or $emit (upward to scope hierarchy) to transmit an event form one controller to the other.
然后,你会在登记触发你的函数接收的事件。请参见 http://docs.angularjs.org/api/ng.$rootScope .Scope#$上。
Then you would register an event on the receiver that triggers your function. See http://docs.angularjs.org/api/ng.$rootScope.Scope#$on.