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
OR
How can this be done? |
|||||||||
|
The syntax is the following:
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:
|
|||||||||||||||||||||
|
EDIT: It appears that you have to break out of the current $apply() cycle. One way to do this is using $timeout():
See fiddle: http://jsfiddle.net/t34z7/ |
|||||||||||||||||||||
|
Just in case everybody see's it, I added additional duplicating answer with an important line which will not break event propagation
|
|||
|
You can do like
|
||||
|
Checkout the Jsfiddle Or Here I have added a simple Trigger Handler:
|
|||||
|
This following solution works for me :
instead of :
|
|||||||||||||||||
|
I think it would be best to avoid "clicking" on the elements. Instead one should try to change the underlying data (ng-model), which (almost always) is watched by the element. An example with a checkbox:
|
||||
|
The best solution is to use:
Because the angularjs triggerHandler( 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 |
|||
|