JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<div ng-controller="AppCtrl">
<h2> {{count}} </h2>
<button ng-click="plus()"> 1 </button>
<button dir count="count" plus="plus()"> 2 </button>
</div>
JavaScript
angular.module('app', [])
.controller('AppCtrl', function($scope) {
$scope.count = 0;
$scope.plus = function() {
$scope.count += 1;
};
})
.directive('dir', function() {
return {
restrict: 'A',
scope: {
count: '=',
plus: '&'
},
link: function(scope, element, attrs, ctrl) {
element.on('mousedown', function(event) {
scope.plus();
scope.count += 1;
});
}
}
});