Skip to content

Instantly share code, notes, and snippets.

@skeep
Created September 19, 2013 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skeep/6629419 to your computer and use it in GitHub Desktop.
Save skeep/6629419 to your computer and use it in GitHub Desktop.
A Pen by Suman Paul.
<div ng-app="myApp">
<div ng-controller="parentCtrl">
Name, <input type="text" ng-model="name">
<br>
My Child is {{ child }}
<div ng-controller="childCtrl">
Name : <input type="text" ng-model="name">
<br>
My Parnets is <strong>{{ parent }}</strong>
</div>
</div>
</div>
var myApp = angular.module('myApp',[]);
function parentCtrl($scope) {
$scope.name = 'parent';
$scope.$watch('name', function(n, o){
console.debug('Parent Changed');
$scope.$broadcast('parent_changed', $scope.name);
});
$scope.$on('child_changed', function(e, m){
console.log(e, m);
$scope.child = m;
});
}
function childCtrl($scope) {
$scope.name = 'child';
$scope.$watch('name', function(n, o){
console.debug('Child Changed');
$scope.$emit('child_changed', $scope.name);
});
$scope.$on('parent_changed', function(e, m){
console.log(e, m);
$scope.parent = m;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment