Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<h3>communication between controllers, new way</h3>
<div ng-controller="Controller0">
    Controller0 :<input ng-model="sharedService.messageToShare" >
    <button ng-click="handleClick();">share</button>
</div>
<div ng-controller="Controller1">
    Controller1 :<input ng-model="sharedService.sharingMessage" >
</div>
<div ng-controller="Controller2">
    Controller2 :<input ng-model="sharedService.sharingMessage" >
</div>
  
</body>
</html>
 
var app = angular.module('myApp', []);
app.controller('Controller0', function($scope,sharedService) {
  $scope.sharedService = sharedService;
    
  $scope.handleClick = function() {
    //if you really want ...
    sharedService.sharingMessage = sharedService.messageToShare;
  };
});
app.controller('Controller1', function($scope,sharedService) {
  $scope.sharedService = sharedService;
});
app.controller('Controller2', function($scope,sharedService) {
  $scope.sharedService = sharedService;
});
app.factory('sharedService', function() {
    var shared = {};
    shared.messageToShare = '';
    shared.sharingMessage = '';
   
    return shared;
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
jeremykopro
0viewers