AngularJS How to Trigger a Click

This is a simple trick to trigger a click by not clicking the thing that is triggering the click. If you got confused with the sentence, in lay man terms, it means I am calling a service to click the button for me.

AngularJS

So, if you are here to learn how to do this, look through here.

Here is a sample html

<div id='player'>
<div id="CW" ng-click="getProfile('conley')">Conley Woods</div>
</div>

This might not be a proper example, but let’s say if you were trying to emulate the click trigger (if there is no way to automate it), this is the solution below.


$timeout(function() {
angular.element('#CW').triggerHandler('click');
}, 0);

What this does is look for the id and perform a click action. Voila.

Leave a Reply