OLD | NEW |
1 part of angular.mock; | 1 part of angular.mock; |
2 | 2 |
3 /* | 3 /* |
4 * Use Probe directive to capture the Scope, Injector and Element from any DOM | 4 * Use Probe directive to capture the Scope, Injector and Element from any DOM |
5 * location into root-scope. This is useful for testing to get a hold of | 5 * location into root-scope. This is useful for testing to get a hold of |
6 * any directive. | 6 * any directive. |
7 * | 7 * |
8 * <div some-directive probe="myProbe">..</div> | 8 * <div some-directive probe="myProbe">..</div> |
9 * | 9 * |
10 * rootScope.myProbe.directive(SomeAttrDirective); | 10 * rootScope.myProbe.directive(SomeAttrDirective); |
11 */ | 11 */ |
12 @NgDirective(selector: '[probe]') | 12 @Decorator(selector: '[probe]') |
13 class Probe implements NgDetachAware { | 13 class Probe implements DetachAware { |
14 final Scope scope; | 14 final Scope scope; |
15 final Injector injector; | 15 final Injector injector; |
16 final Element element; | 16 final Element element; |
17 final NodeAttrs _attrs; | 17 String _probeName; |
18 | 18 |
19 Probe(this.scope, this.injector, this.element, this._attrs) { | 19 Probe(this.scope, this.injector, this.element) { |
20 scope.rootScope.context[_attrs['probe']] = this; | 20 _probeName = element.attributes['probe']; |
| 21 scope.rootScope.context[_probeName] = this; |
21 } | 22 } |
22 | 23 |
23 void detach() { | 24 void detach() { |
24 scope.rootScope.context[_attrs['probe']] = null; | 25 scope.rootScope.context[_probeName] = null; |
25 } | 26 } |
26 | 27 |
27 /** | 28 /** |
28 * Retrieve a Directive at the current element. | 29 * Retrieve a Directive at the current element. |
29 */ | 30 */ |
30 directive(Type type) => injector.get(type); | 31 directive(Type type) => injector.get(type); |
31 } | 32 } |
32 | 33 |
OLD | NEW |