我的 AngularJS 应用程序中有两个控制器。他们看起来像:
controller("AppCtrl", function($scope){
//do some stuff here
})
和
controller("ChatCtrl", function($scope, chat_service){
$scope.init = function(){
chat_service.identify(...nick and some other data...);
chat_service.on_users_update(function(){...do stuff here...});
}
//some other methods
$scope.init();
})
请注意,这AppCtrl是我的主控制器,它会在您打开应用程序时执行。问题是我想ChatCtrl.init()从我的 打电话AppCtrl,但我不知道怎么做。
显然,$rootScope.$emit()并且在 ``$emit```` 发生时$rootScope.$on(),$on()部分(将在 中ChatCtrl)尚未执行,因此不会起作用。
而且我真的不想在AppCtrl.
init()有没有办法打电话AppCtrl?