I have a directive that generates a button, and when I click this button a counter increases by 1. This policy is inserted in two places in my index.html. I would like that when I clicked on any of the buttons, the two were changed ...
Here is my code:
index.html:
<div ng-app='demo'>
<button-directive></button-directive>
<button-directive></button-directive>
</div>
app.js:
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;
};
}]);
Here's a fiddle: link