0

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

4
  • docs.angularjs.org/api/ng/directive/ngClick Commented Oct 9, 2014 at 8:27
  • What are you trying to achive by using JQuery? Commented Oct 9, 2014 at 8:37
  • You can make an initial call to clickDetails in myCtrl, since controller is created at each view, you will be sure that clickDetails will be called for each view request. Commented Oct 9, 2014 at 8:49
  • @cubbuk I need to show an message to user untill he close that message box. Message box and anchor is dynamic. So, i keep the id of anchor into a cookie and on page load use that cookie to identify which message will be display. There are multiple messages. Commented Oct 9, 2014 at 9:23

1 Answer 1

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

try it?

http://jsfiddle.net/90nnmv6s/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.