I want to trigger ng-click
of an element at runtime like:
_ele.click();
OR
_ele.trigger('click', function());
How can this be done?
I want to trigger ng-click
of an element at runtime like:
_ele.click();
OR
_ele.trigger('click', function());
How can this be done?
This following solution works for me :
instead of :
You can do like
This code will not work (throw an error when clicked):
You need to use the querySelector as follows:
The best solution is to use:
Because the angularjs triggerHandler(
angular.element(domElement).triggerHandler('click')
) click events does not bubble up in the DOM hierarchy, but the one above does - just like a normal mouse click.https://docs.angularjs.org/api/ng/function/angular.element
http://api.jquery.com/triggerhandler/
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click
Just in case everybody see's it, I added additional duplicating answer with an important line which will not break event propagation
Using plain old JavaScript worked for me:
document.querySelector('#elementName').click();