在AngularJS,你如何找到一个网页上的所有范围? [英] In AngularJS, how do you find all the scopes on a page?
本文介绍了在AngularJS,你如何找到一个网页上的所有范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一旦我们在手的范围,我们可以导航到它的根和探索范围层次。
Once we have a scope in hand, we can navigate to its root and explore the scope hierarchy.
但有一个直接的方式找到一个页面上的所有范围?
But is there a direct way to find all the scopes on a page?
同样给出一个HTML元素,有没有直接的方式找到自己的封闭范围是什么?
Likewise given an HTML element, is there a direct way to find its enclosing scope?
推荐答案
你可以看到所有使用该CSS选择器在页面上的作用域
you can see all of the scopes on the page using this CSS selector
.ng-scope { border: 1px solid red; }
和所有绑定的:
.ng-binding { border: 1px solid red; }
您可以再由DOM元素转换为选择器检索它们
You can then retrieve them by converting the DOM element into selector
var selector = angular.element(some_dom_element);
然后使用选择以检索范围/控制器/注射器
Then use the selector to retrive the scope/controller/injector
var scope = selector.scope();
var controller = selector.controller();
var injector = selector.injector();
这篇关于在AngularJS,你如何找到一个网页上的所有范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文