Cami Rodriguez Cami Rodriguez - 3 months ago 25
AngularJS Question

How to catch event onclick without ng-click Angular.js

I'm developing an Angular App but I want to catch onclick event without ng-click, I want to use something like that

$scope.onClick(...)

Answer

AngularJs use directive to operate dom. you can add a directive like this.

AngularJs

YourApp.directive('testClick', function () {
    return {
        restrict: 'A',
        link: function (scope, element) {
            element.onclick = function() {
                //do some thing.
            }
        }
    }
})

html

<button test-click>Test Click</button>