Directive transclude example

by Dor Cohen

HTML

<script src="http://code.angularjs.org/1.1.3/angular.js"></script>
<div>
  <div my-directive>
    <button>some button</button>
    <a href="#">and a link</a>
  </div>
</div>

JavaScript

var myApp = angular.module('myApp', []);

myApp.directive('myDirective', function() {
  return {
  	restrict: 'EA',
    transclude: true,
    scope:{
    	format:'='
    },
    controller: ["$scope", "$timeout", function($scope, $timeout) {
    	function updateTime() {
        $scope.time = new Date();
      }

      function setWorkInterval() {
        $timeout(function() {
          updateTime();
          setWorkInterval();
        }, 1000);
      }
      setWorkInterval();
    }],
    template: '<div class="something"> {{time}} </div>'
    //templateUrl: 'myHtml.html"
  }
});