Angular JS: Using a service to communicate between two controllers
HTML
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<input type="text" ng-model="service.name">
{{service.name}}
</div>
<div><!-- some crap to fill the page with --></div>
<div ng-controller="MyCtrl2">
{{service.name}}
</div>
</div>
JavaScript
angular.module("myApp", [])
.service("myService", function(){
this.name = "hello";
});
function MyCtrl($scope, myService) {
$scope.service = myService;
}
function MyCtrl2($scope, myService) {
$scope.service = myService;
}