AngularJS 1.4
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://cdn.rawgit.com/angular-ui/bootstrap-bower/0.13.4/ui-bootstrap-tpls.js"></script>
<div ng-app="SharingDataBetweenControllers" ng-scope>
<div ng-controller="Controller5a">
first controller:<input ng-model="text" ng-change='set()'/>
</div>
<div ng-controller="Controller5b">
second controller: {{text}}
</div>
</div>
JavaScript
var module = angular.module('SharingDataBetweenControllers', []);
module.controller('Controller5a',function($scope) {
$scope.text='hello';
$scope.$watch('text',function(newValue,oldValue){
//console.log(newValue);
//this with send the message to $rootScope
$scope.$emit('share',$scope.text);
})
});
module.controller('Controller5b', function($scope,$rootScope) {
$rootScope.$on('share', function(event,response){
console.log(response);
$scope.text = response;
})
});