Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-controller="ctrl">
  
  <div>{{data}}</div>
  <div shadow="data">
    <input ng-model="data.foo">
    <input ng-model="data.bar">
    <button ng-click="commit()">save</button>
  </div>
  
</body>
</html>
 
angular.module('app', [])
  
.controller('ctrl', function($scope) {
  $scope.data = {
    foo: 'abcd',
    bar: 'efgh'
  };    
})
.directive('shadow', function() {
  return {
    scope: {
      target: '=shadow'            
    },
    link: function(scope, el, att) {
      scope[att.shadow] = angular.copy(scope.target);
      scope.commit = function() {
        scope.target = angular.copy(scope[att.shadow]);
      };
    }
  };
});
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers