Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="App">
<head>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//code.angularjs.org/1.2.26/angular.js"></script>
  <meta charset="utf-8">
  <title>Demo</title>
</head>
<body>
  <div my-directive>
    <input type="text" value="asdasd">
  </div>
  <div my-directive>
    <input type="email" value="asdasd">
  </div>
</body>
</html>
 
angular.module('App', []).directive('myDirective', function($timeout) {
  var content={};
  var loadedDirs;
  return {
    scope:true,
    template: function(elm){
      loadedDirs = loadedDirs || angular.element(document.querySelectorAll('[my-directive]'));
       //Save the element in its respective index    
      content[loadedDirs.index(elm)] = elm.html();
      return '<div>Template<div><pre>{{orig}}</pre></div></div>'
    },
    link: function(scope, element) {
      var idx = loadedDirs.index(element);
      
       scope.orig = content[idx];
      //remove key
      delete content[idx];
      if(!Object.keys(content)){ //Remove reference to laodedDirs
         loadedDirs = null;
        }  
      }
  };
});
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers