3
I have a directive that generates a button, and when I click this button a counter increases 1. This directive is inserted in two places in my index.html. I wish that when I clicked on one of the buttons, the two would be changed...
Just follow 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 is a fiddle: http://jsfiddle.net/dfalbel/1kyq5e15/
heightened the response
– iuristona