3

I am working on a website based on angular js.

Currently, I have written about 5000 line code in angular js.

So I have to make some changes without touching my angular js.

I want something like this:

$(document).on('click','#buttonid',function(){ //performing some necessary task then call ng-click method ngclickmethod(); }); 

HTML Code:

<a ng-click="ngclickmethod()" id="buttonid"> 

Please advise how can I achieve that.

Many Thanks

9
  • Your button's click event (registered by angular) will be executed regardless, angular also just register the handler. And in this case you are getting the event when bubbled to the document. So angular click handler will most possibly get executed. Can you provide some practical scenario? Anyways you just have to do angular.element(this).scope().ngclickmethod() Commented Sep 4, 2014 at 21:47
  • Yes, that's my point, I want to execute click event first and then ng-click event. I already have register handler for the method Commented Sep 4, 2014 at 21:51
  • 1
    Then you should not use event delegation. You should register the event directly on the element. plnkr.co/edit/O25ZXZCcgZGss7O29ULt?p=preview .So basically you would have to keep the script tag on your html which has this anchor tag and bind the event to it. Commented Sep 4, 2014 at 21:52
  • can I disable ng-click until I perform some necessary operation, then enable and execute ng-click method? Commented Sep 4, 2014 at 21:53
  • So code will be look like this right? $(document).on('click','#buttonid',function(){ //performing some necessary task then call ng-click method angular.element(this).scope().ngclickmethod() }); Commented Sep 4, 2014 at 21:56

1 Answer 1

2

So it looks like you are trying to call an angular function outside of angular. Try this..

angular.element(document.getElementById('yourControllerElementID')).scope().ngclickmethod(); 

this will call the method you want. Be sure the controller element ID is the controller that contains the ngclickmethod function

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

1 Comment

Ya...This code is working ...Thanks everybody taking the part of this discussion...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.