Angular directive

Basic with angular custom directive.

by Rishi Kumar

HTML

<script src="https://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-app="app">
  <div ng-controller="MyCtrl1">
    <test data="name"></test>
  </div>
  <div ng-controller="MyCtrl2">
    <test data="name"></test>
  </div>
</div>

JavaScript

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

app.controller("MyCtrl1",function($scope) {
    $scope.name = 'Batman';
})
app.controller("MyCtrl2",function($scope) {
    $scope.name = 'Superman';
})
app.directive("test",function(){
	console.log("directive");
  return {
  		restrict : "E",
      scope : {
      	data :"=data"
      },
			template : "<div>{{data}}</div>"
  }
})