AngularJS - 查找元素根据属性值 [英] AngularJS - Find Element by Attribute Value
问题描述
我试图用AngularJS查询我的观点的DOM。我需要得到所有具有属性数据布局与顶级的价值元素。 jQuery中,我会做这样的:
I'm trying to use AngularJS to query the DOM of my view. I need to get all of the elements that have the attribute 'data-placement' with the value of 'top'. In jQuery, I would do this:
var elements = $('[data-placement="top"]');
不过,我不知道如何与AngularJS做到这一点。谁能告诉我如何做到这一点?
However, I don't know how to do it with AngularJS. Can someone tell me how to do this?
感谢您!
推荐答案
在AngularJS你不会从控制器直接做DOM操作,你应该创建一个指令到。该指令内部如你所愿,你可以使用jQuery。
In AngularJS you won't do direct DOM manipulation from the controller, you should create a directive to to that. Inside the directive you can use JQuery as you wish.
反正你我想你可以使用 angular.element()
与JQlite选择,这里的的 angular.element 。
Anyway you I think you can use angular.element()
with a JQlite selector, here's the documentation of angular.element.
例如:
// find('#id')
angular.element(document.querySelector('#id'))
这篇关于AngularJS - 查找元素根据属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!