Event is not working during ng-change

2,918 views
Skip to first unread message

Kingsly Azariah

unread,
Mar 12, 2014, 1:18:29 PM3/12/14
to ang...@googlegroups.com


I have 3 three checkbox on ng-change/ng-click the $event is passed as parameter, $event is undefined during ng-change event but it works fine for ng-click.

Code is the below URL
http://jsfiddle.net/kingsly/cv5Gp/12/
first checkbox has ng-change
next two checkbox ng-click




Justin Walsh

unread,
Mar 12, 2014, 2:09:25 PM3/12/14
to ang...@googlegroups.com
Hi Kingsly, 

The documentation for ngClick mentions
Event object is available as $event

The documentation for ngChange does not mention that the event object is available.

That explains the behaviour that you are seeing.

Sander Elias

unread,
Mar 12, 2014, 2:12:47 PM3/12/14
to ang...@googlegroups.com
Hi Kingsly,

ngChange is an directive, not an event-handler. The working is quite different. ngChange works by setting an scope.$watch, ngClick works by catching an event. 
This behaviour is as documented, so this is a feature, not a bug.
I understand your confusion, it's an easily made mistake. If you want, you can create your own event handler using a (there is some irony here ;)) directive!
What is it you are trying to accomplish? Perhaps I can help you finding an alternative solution.

Regards
Sander


Kingsly Azariah

unread,
Mar 13, 2014, 10:18:38 AM3/13/14
to ang...@googlegroups.com
Hi Sander

    I need to know which check box(id) was clicked during ngChange, I cannot us ng-click.

Regards
Kingsly

Sander Elias

unread,
Mar 13, 2014, 10:59:05 AM3/13/14
to ang...@googlegroups.com
Hi,

It is not that hard to make your own directive to do just that:

However, I think you are still stuck in a jQuery way of thinking. This kind of things you seldom need in angular!

Regards
Sander

Zhi Bin

unread,
Dec 4, 2015, 10:56:21 PM12/4/15
to AngularJS
I think this is a bug, no a feature. 

在 2014年3月13日星期四 UTC+8下午10:59:05,Sander Elias写道:
Reply all
Reply to author
Forward
0 new messages