I am trying to update the parent controller $scope
value into child controller $scope
value using broadcasting as expected working, but not updating while trying to update the child $scop
e value to parent $scope
value by emit function. This is my code:
app.controller('FirstCtrl', function($rootScope, $scope) {
$scope.firstRegister = function() {
$rootScope.$broadcast('broadcast', $scope.name)
};
$scope.$on('emit', function(events, args) {
$scope.name = args;
});
});
app.controller('SecondCtrl', function($rootScope, $scope) {
$scope.$on('broadcast', function(events, args) {
$scope.name = args;
});
$scope.secondRegister = function() {
$rootScope.$emit('emit', $scope.name)
};
<div ng-controller="FirstCtrl" class="ng-scope">
<input ng-model="name" />
<button ng-click="firstRegister()">Parent</button>
<div ng-controller="SecondCtrl" class="ng-scope">
<input ng-model="name" />
<button ng-click="secondRegister()">Child</button>
</div>
</div>
plnkr link : http://plnkr.co/edit/l9qD0ZO4MptnWx6u3U9c?p=preview