How have a link like
<a href="" ng-click="someAction()">Some text</a>
and I want to invoke ngClick
action from jQuery:
$('a').click()
But it doesn't work: someAction()
not invoked. Also didn't work
$('a').trigger('click')
Is it possible to invoke someAction()
from jQuery?
Nevermind the apply cycles and timeouts, here you are:
$('a').dispatchEvent(new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
}));
I think it's strange that it's not working, I get it working with both
angular.element('a[ng-click="someAction()"]')
and
$('a[ng-click="someAction()"]')
as selectors, and both click()
and trigger('click')
to fire the clickhandler.
See http://plnkr.co/edit/6VMavwVImXAonSp8xZrI?p=preview (Watch the console)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With