can we pass element in ng-click?

30,498 views
Skip to first unread message

Abdul Azeez Shaik

unread,
Aug 20, 2012, 8:42:54 AM8/20/12
to ang...@googlegroups.com
Dear all,

Can we pass an element to ng-click() function?
In the below example, 

<input type="checkbox"  ng-checked="mainfilter.checked" ng-change="selectChildFilters(element)"/>

I need to pass this respective input element in ng-change or ng-click events().

Is there a way to do this?

Thanks,

Abdul

Ricardo Bin

unread,
Aug 20, 2012, 9:52:15 AM8/20/12
to ang...@googlegroups.com
You can get it using $event and retrieve srcElement or target from it.

Abdul Azeez Shaik

unread,
Aug 20, 2012, 10:13:18 AM8/20/12
to ang...@googlegroups.com
Thanks for this Ricardo. I tried this and its working great.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

vinay...@gmail.com

unread,
Aug 20, 2012, 3:39:00 PM8/20/12
to ang...@googlegroups.com
Why would you want to access the dom element in the controller? Controllers should not have any dom manip code, directives is a good place for such things. If you could tell us what you are trying to do we could suggest more ideas.

For ex: Ricardo's fiddle without dom manip:


Vinay.

Abdul Azeez Shaik

unread,
Aug 21, 2012, 5:10:25 AM8/21/12
to ang...@googlegroups.com
Hi Vinay,

I am using this in directive's template. As per the requirement, i need to call the slieToggle() function of jquery on the element. Ricardo's fiddle helped me to access the element inside the ng-click function()

Also,Thanks for putting the point once again that directives are the efficient way of changing/accessing the DOM.

Regards,
 Abdul

--

Andy Joslin

unread,
Aug 21, 2012, 5:38:46 AM8/21/12
to ang...@googlegroups.com
If you're writing a directive, you should already have the element and not have to do this, though o-:
Reply all
Reply to author
Forward
0 new messages