@@ -10,34 +10,44 @@ import 'package:angular/core/module_internal.dart';
10
10
import 'package:angular/core_dom/module_internal.dart' ;
11
11
12
12
/**
13
- * Return the closest [ElementProbe] object for a given [Element] .
13
+ * Return the [ElementProbe] object for the closest [Element] in the hierarchy.
14
+ *
15
+ * The node parameter could be:
16
+ * * a [dom.Node] ,
17
+ * * a CSS selector for this node.
14
18
*
15
19
* **NOTE:** This global method is here to make it easier to debug Angular
16
20
* application from the browser's REPL, unit or end-to-end tests. The
17
21
* function is not intended to be called from Angular application.
18
22
*/
19
- ElementProbe ngProbe (dom.Node node) {
20
- if (node == null ) {
21
- throw "ngProbe called without node" ;
23
+ ElementProbe ngProbe (nodeOrSelector) {
24
+ var errorMsg;
25
+ var node;
26
+ if (nodeOrSelector == null ) throw "ngProbe called without node" ;
27
+ if (nodeOrSelector is String ) {
28
+ var nodes = ngQuery (dom.document, nodeOrSelector);
29
+ if (nodes.isNotEmpty) node = nodes.first;
30
+ errorMsg = "Could not find a probe for the selector '$nodeOrSelector ' nor its parents" ;
31
+ } else {
32
+ node = nodeOrSelector;
33
+ errorMsg = "Could not find a probe for the node '$node ' nor its parents" ;
22
34
}
23
- var origNode = node;
24
35
while (node != null ) {
25
36
var probe = elementExpando[node];
26
37
if (probe != null ) return probe;
27
38
node = node.parent;
28
39
}
29
- throw "Could not find a probe for [$ origNode ]" ;
40
+ throw errorMsg ;
30
41
}
31
42
32
-
33
43
/**
34
44
* Return the [Injector] associated with a current [Element] .
35
45
*
36
46
* **NOTE**: This global method is here to make it easier to debug Angular
37
47
* application from the browser's REPL, unit or end-to-end tests. The function
38
48
* is not intended to be called from Angular application.
39
49
*/
40
- Injector ngInjector (dom. Node node ) => ngProbe (node ).injector;
50
+ Injector ngInjector (nodeOrSelector ) => ngProbe (nodeOrSelector ).injector;
41
51
42
52
43
53
/**
@@ -47,7 +57,7 @@ Injector ngInjector(dom.Node node) => ngProbe(node).injector;
47
57
* application from the browser's REPL, unit or end-to-end tests. The function
48
58
* is not intended to be called from Angular application.
49
59
*/
50
- Scope ngScope (dom. Node node ) => ngProbe (node ).scope;
60
+ Scope ngScope (nodeOrSelector ) => ngProbe (nodeOrSelector ).scope;
51
61
52
62
53
63
List <dom.Element > ngQuery (dom.Node element, String selector,
@@ -70,14 +80,11 @@ List<dom.Element> ngQuery(dom.Node element, String selector,
70
80
}
71
81
72
82
/**
73
- * Return a List of directive controllers associated with a current [Element] .
83
+ * Return a List of directives associated with a current [Element] .
74
84
*
75
85
* **NOTE**: This global method is here to make it easier to debug Angular
76
86
* application from the browser's REPL, unit or end-to-end tests. The function
77
87
* is not intended to be called from Angular application.
78
88
*/
79
- List <Object > ngDirectives (dom.Node node) {
80
- ElementProbe probe = elementExpando[node];
81
- return probe == null ? [] : probe.directives;
82
- }
89
+ List <Object > ngDirectives (nodeOrSelector) => ngProbe (nodeOrSelector).directives;
83
90
0 commit comments