此处不做详细讲解,提供一个小例子,看了便懂
<html ng-app=""> <div ng-controller="ctrlController"> <div ng-controller="ctrl1Controller"></div> <div ng-controller="ctrl2Controller"></div> </div> </html> <script> function ctrl1Controller($scope){ $scope.$emit(‘event‘, data); } function ctrlController($scope){ $scope.on(‘event‘, function(event, data){ $scope.$broadcast(‘event1‘, data); }) } function ctrl2Controller($scope){ $cope.$on(‘event1‘, function(event, data){ //do some thing }) } </script>
时间: 2024-10-11 00:20:16