Angular Events - $broadcast and $emit

A simple example of sending data around, not a best practice by any means. Data-binding is what all the cool kids are doing!

HTML

<div ng-app="MyApp">
    <div ng-controller="firstCtrl">
        
        <div ng-if="test">Test</div>
        
        <div ng-controller="secondCtrl">
            <button ng-click="func2()">func2</button>
        </div>
    </div>
    <br>
    
</div>

JavaScript

var app = angular.module('MyApp', []);


app.controller('firstCtrl', function($scope,$rootScope) {

  $scope.$on('someEvent', function(event, data) { console.log(data); });

});

app.controller('secondCtrl', function($scope,$rootScope) {

$scope.$emit('someEvent', [1,2,3]);
   
});