Nitin Kumar Soni
Nitin Kumar Soni

Reputation: 198

ng-click not working on programatically triggering click event

I used jQuery many times I am new to angular js.

I called a function on click event of a link. When i click on link it work fine and code is as below

<div data-ng-controller="myCtrl" >    
<a id="clickBtn" data-ng-click="clickDetails()" ></a>
</div>

But when i trigger the click event programmatically on page load. This function not called "clickDetails". I am triggering click event using this code:

$(document).ready(function () {
    $('#clickBtn').trigger('click');
});

Any hint or suggestion will be appreciated.

Thanks in advance

Upvotes: 0

Views: 418

Answers (1)

Parfait
Parfait

Reputation: 1750

$timeout(function () {
    angular.element(document.getElementById('clickBtn')).triggerHandler('click');
}, 0);

try it?

http://jsfiddle.net/90nnmv6s/

Upvotes: 1

Related Questions