如何从$ rootScope中获取$ scope并修改它。$ on事件处理程序?
angular.module('Foo')
.controller('BarCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
$scope.x = {};
$rootScope.$on('myEvent', function(event, data){
if(data){
//how to reach BarCtrl $scope.x here?
}else{
//same here
}
})
}])
答案 0 :(得分:1)
只需使用$scope
变量
$rootScope.$on('myEvent', function(event, data){
$scope.x = data;
});