angular同一个页面多个controller值传递

//父级
//自己 click me
//子级
//平级
phonecatControllers.controller('SelfCtrl', function($scope) {  
    $scope.click = function () {  
        $scope.$broadcast('to-child', 'child');  
        $scope.$emit('to-parent', 'parent');  
    }  
});  
  
phonecatControllers.controller('ParentCtrl', function($scope) {  
    $scope.$on('to-parent', function(d,data) {  
        console.log(data);         //父级能得到值  
    });  
    $scope.$on('to-child', function(d,data) {  
        console.log(data);         //子级得不到值  
    });  
});  
  
phonecatControllers.controller('ChildCtrl', function($scope){  
    $scope.$on('to-child', function(d,data) {  
        console.log(data);         //子级能得到值  
    });  
    $scope.$on('to-parent', function(d,data) {  
        console.log(data);         //父级得不到值  
    });  
});  
  
phonecatControllers.controller('BroCtrl', function($scope){  
    $scope.$on('to-parent', function(d,data) {  
        console.log(data);        //平级得不到值  
    });  
    $scope.$on('to-child', function(d,data) {  
        console.log(data);        //平级得不到值  
    });  
}); 


用$broadcast赋的值,只能子级能得到值,父级得不到,用$emit赋的值,只能父级得到值,子级得不到。平级都得不到值

你可能感兴趣的:(angularjs)