What's the best way to .find using jqLite?

6,813 views
Skip to first unread message

Lior M

unread,
Jun 26, 2013, 3:02:13 PM6/26/13
to ang...@googlegroups.com
hi all

I'm trying to remove jquery from my Angular.js app in order to make it lighter, and put Angular's jqLite instead. But the app makes heavy use of find('#id') and find ('.classname'), which are not supported by jqLite, only 'tag names' (as per documentation)

wondered what do u feel would be the best approach to change it. One approach I thought about is to create custom HTML tags. for example: change
<span class="btn btn-large" id="add-to-bag">Add to bag</span>

to

<a2b style="display:none;"><span class="btn btn-large" >Add to bag</span></a2b>

and

$element.find('#add-to-bag') 

to

$element.find('a2b')

Any thoughts? any other ideas (i.e. get away without .find at all)?

thanks

Lior

Ricardo Bin

unread,
Jun 26, 2013, 3:42:20 PM6/26/13
to ang...@googlegroups.com
Theres a very easier way to do this.

Use native querySelector or even $document service

Lior Messinger

unread,
Jun 26, 2013, 4:27:49 PM6/26/13
to ang...@googlegroups.com
wow, cool! thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/tRrM5gtub4g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

George Ivanov

unread,
May 23, 2014, 9:29:05 PM5/23/14
to ang...@googlegroups.com
Another way will be to use $element[0].querySelector('.className'); 

Ryan Cole

unread,
Jul 28, 2014, 2:17:16 PM7/28/14
to ang...@googlegroups.com
Ha! I wanted to slap myself after reading this. It's amazing how dependent you get on jQuery after a while. Eevn to the point that you forget that you can find dom elements without it!

Martin Spierings

unread,
Jul 28, 2014, 4:54:29 PM7/28/14
to ang...@googlegroups.com
Quick question: why do you need to find the element? Cause i'm guessing you are trying to get some data but why not use an ng-click function on it with some var included that will trigger something in your controller (to bind the data to a certain var in $scope).
You can also use a ng-model or something to get around finding items.

Op woensdag 26 juni 2013 21:02:13 UTC+2 schreef Lior M:
Reply all
Reply to author
Forward
0 new messages