A Pen by Suman Paul on CodePen.
Created
September 19, 2013 20:31
-
-
Save skeep/6629419 to your computer and use it in GitHub Desktop.
A Pen by Suman Paul.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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