<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
</head>
<body ng-app="myApp" >
<div ng-controller="myCtrl1">
<input type="text" ng-model="name"/>
<button ng-click="getName()">Submit</button>
</div>
<div ng-controller="myCtrl2">
**_{{user}}_**
</div>
<script>
var app = angular.module('myApp',[]);
app.controller('myCtrl1', function($scope, $rootScope){
$scope.getName = function(){
debugger;
_**$rootScope.userName = $scope.name;**_
}
});
app.controller('myCtrl2', function($scope, $rootScope){
**_$scope.user = $rootScope.userName;_**
console.log($scope.user);
});
</script>
</body>
</html>
This is my code onclick of the button i have to update that in another controller but it is not happening.
Why two way binding is not working?