Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="toDo" >
<head>
<meta name="description" content="Simplest Controllers sharing Factory" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  
  <div ng-controller="One">
    <div>Type and see your text in the other box:</div>
    <input ng-model="data.string">
  </div>
  
  <hr>
  
  <div ng-controller="Two">
    <div>And now type here: </div>
    <input ng-model="data.string"
  </div>
  
</body>
</html>
 
angular.module('toDo',[])
.factory('dataService', function() {
  var _dataObj = {};
  return {
    dataObj: _dataObj
  };
})
.controller('One', function($scope, dataService) {
  $scope.data = dataService.dataObj;
})
.controller('Two', function($scope, dataService) {
  $scope.data = dataService.dataObj;
})
;
Output

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

Dismiss x
public
Bin info
dmitrizpro
0viewers