You can easily create a custom click directive using link function in angular js.
html source
I have added a custom attribute named custom-click in the button element for handling the click event which is similar to angular ng-click. Now i am going to write a custom directive for this custom attribute.
angular.module('app', []);
angular.module('app').controller('myController', function ($scope) {
$scope.obj = { message: "Not Clicked" };
$scope.callMethod = function (p) {
p.message = "Clicked!!";
}
});
angular.module('app').directive("customClick", function ($parse) {
return {
link: function (scope, element, attrs) {
var func = $parse(attrs["customClick"]);
element.on('click', function () {
scope.$apply(function () {
func(scope);
});
});
}
}
});
when you clicked the button you can see the message ‘Clicked !!’ in the h1 tag.