Simple Angular Binding demo with directive

Externalize the time into a separate directive component.

by Daniel Falbel

HTML

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.angularjs.org/1.0.6/angular.min.js"></script>
<div ng-app='demo'>
    <button-directive></button-directive>
    <button-directive></button-directive>
</div>

JavaScript

var demo = angular.module('demo', []);
demo.directive('buttonDirective', function($parse) {
    return {
        restrict: 'E',
        template: '<button ng-controller="MyCtrl" ng-click="increment()">{{count}}</button>'
    };
});

demo.controller('MyCtrl', ['$scope', function($scope){
    $scope.count = 0;
    $scope.increment = function(){
        $scope.count = $scope.count + 1;
    };
}]);