How to trigger ngClick programmatically


I want to trigger ng-click of an element at runtime like:;


_ele.trigger('click', function());

How can this be done?


The syntax is the following:

function clickOnUpload() {
  $timeout(function() {

// Using Angular Extend
angular.extend($scope, {
  clickOnUpload: clickOnUpload

// OR Using scope directly
$scope.clickOnUpload = clickOnUpload;

More info on Angular Extend way here.

If you are using old versions of angular, you should use trigger instead of triggerHandler.

If you need to apply stop propagation you can use this method as follows:

<a id="myselector" ng-click="clickOnUpload(); $event.stopPropagation();">

Answered By – clopez

Answer Checked By – Katrina (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.