AngularJS:如何使用jqLite到.find? [英] AngularJS: How to .find using jqLite?
问题描述
我想从我的Angular.js的应用程序,以使其更轻,并把角的jqLite改为移除jQuery的。但应用程序大量使用查找('#ID),并找到('.classname),这是不被支持jqLite,只有标签名称(按文档)
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)
想知道什么ü觉得是改变它的最佳方法。我想到一种方法的是创建自定义HTML标签。例如:
改变结果
<跨度类=BTN BTN-大ID =添加到包>添加到包< / SPAN>
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>
到
<a2b style="display:none;"><span class="btn btn-large" >Add to bag</span></a2b>
和
$element.find('#add-to-bag')
到
$element.find('a2b')
有什么想法?其他的想法?
Any thoughts? other ideas?
感谢
利奥尔
推荐答案
从本质上讲,并通过@凯文-B为提到的:
Essentially, and as-noted by @kevin-b:
// find('#id')
angular.element(document.querySelector('#id'))
//find('.classname'), assumes you already have the starting elem to search from
angular.element(elem.querySelector('.classname'))
注意:如果您正在寻找从你的控制器做到这一点,你可能想看看在的开发人员指南和重构你的presentation逻辑放到合适的指令(例如&lt; A2B ...&GT;)。
Note: If you're looking to do this from your controllers you may want to have a look at the "Using Controllers Correctly" section in the developers guide and refactor your presentation logic into appropriate directives (such as <a2b ...>).
这篇关于AngularJS:如何使用jqLite到.find?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!