通过范围的$ id获取DOM元素 [英] Get DOM element by scope $id
本文介绍了通过范围的$ id获取DOM元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我明白我可以通过元素的范围:
I understand I can get the scope by element:
scope = angular.element($0).scope();
scope.$id; // "003"
我如何得到扭转:查找使用范围的$ id
,DOM元素,如 003
我想为调试目的这样做。我的范围树显示的东西,我想找出它来自何处。
I'd like to do this for debugging purposes. My scope tree shows something and I'd like to identify where it came from.
推荐答案
虽然它不是很性感的每一个DOM节点得到的一类NG-范围,所以你可以高技术做这样的事情也许:
Although it's not very sexy each dom node gets a class ng-scope so you could tech do something like this maybe:
function getScope(id) {
var elem;
$('.ng-scope').each(function(){
var s = angular.element(this).scope(),
sid = s.$id;
if(sid == id) {
elem = this;
return false; // stop looking at the rest
}
});
return elem;
}
这篇关于通过范围的$ id获取DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文