JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app
id="parent"
ng-controller="parentCtrl">
<button ng-click="alert()">click me</button>
<div ng-controller="childCtrl">
</div>
</div>
JavaScript
function parentCtrl($scope) {
$scope.alert = function() {
for(var i=0; i<subscribers.length; i++) {
subscribers[i].execute();
}
}
var subscribers = [];
$scope.subscribe = function(child) {
console.log('adding child');
subscribers.push(child);
}
}
function childCtrl($scope) {
this.init = function() {
$scope.$parent.subscribe(this);
}
this.init();
this.execute = function() {
console.log('i am child. hear me roar');
}
}