@@ -4,7 +4,7 @@ describe('ngRef', function() {
4
4
5
5
describe ( 'on a component' , function ( ) {
6
6
7
- var myComponentController , $rootScope , $compile ;
7
+ var myComponentController , attributeDirectiveController , $rootScope , $compile ;
8
8
9
9
beforeEach ( module ( function ( $compileProvider ) {
10
10
$compileProvider . component ( 'myComponent' , {
@@ -13,6 +13,16 @@ describe('ngRef', function() {
13
13
myComponentController = this ;
14
14
}
15
15
} ) ;
16
+
17
+ $compileProvider . directive ( 'attributeDirective' , function ( ) {
18
+ return {
19
+ restrict : 'A' ,
20
+ controller : function ( ) {
21
+ attributeDirectiveController = this ;
22
+ }
23
+ } ;
24
+ } ) ;
25
+
16
26
} ) ) ;
17
27
18
28
beforeEach ( inject ( function ( _$compile_ , _$rootScope_ ) {
@@ -23,9 +33,9 @@ describe('ngRef', function() {
23
33
it ( 'should bind in the current scope the controller of a component' , function ( ) {
24
34
$rootScope . $ctrl = 'undamaged' ;
25
35
26
- $compile ( '<my-component ng-ref="myComponent "></my-component>' ) ( $rootScope ) ;
36
+ $compile ( '<my-component ng-ref="myComponentRef "></my-component>' ) ( $rootScope ) ;
27
37
expect ( $rootScope . $ctrl ) . toBe ( 'undamaged' ) ;
28
- expect ( $rootScope . myComponent ) . toBe ( myComponentController ) ;
38
+ expect ( $rootScope . myComponentRef ) . toBe ( myComponentController ) ;
29
39
} ) ;
30
40
31
41
it ( 'should throw if the expression is not assignable' , function ( ) {
@@ -59,6 +69,11 @@ describe('ngRef', function() {
59
69
expect ( $rootScope . myComponent2 ) . toBe ( myComponentController ) ;
60
70
} ) ;
61
71
72
+ it ( 'should not bind the controller of an attribute directive' , function ( ) {
73
+ $compile ( '<my-component attribute-directive-1 ng-ref="myComponentRef"></my-component>' ) ( $rootScope ) ;
74
+ expect ( $rootScope . myComponentRef ) . toBe ( myComponentController ) ;
75
+ } ) ;
76
+
62
77
it ( 'should not leak to parent scopes' , function ( ) {
63
78
var template =
64
79
'<div ng-if="true">' +
@@ -116,7 +131,7 @@ describe('ngRef', function() {
116
131
expect ( $rootScope . mySpan [ 0 ] . textContent ) . toBe ( 'my text' ) ;
117
132
} ) ) ;
118
133
119
- it ( 'should nullify the dom element value if it is destroyed' , inject ( function ( $compile , $rootScope ) {
134
+ it ( 'should nullify the expression value if the DOM element is destroyed' , inject ( function ( $compile , $rootScope ) {
120
135
var element = $compile ( '<div><span ng-ref="mySpan">my text</span></div>' ) ( $rootScope ) ;
121
136
element . children ( ) . remove ( ) ;
122
137
expect ( $rootScope . mySpan ) . toBe ( null ) ;
@@ -185,7 +200,7 @@ describe('ngRef', function() {
185
200
186
201
187
202
it ( 'should bind an attribute-directive controller if ngRefRead="controllerName" is set' , function ( ) {
188
- var attrDirective2Controller ;
203
+ var attrDirective1Controller ;
189
204
190
205
module ( function ( $compileProvider ) {
191
206
$compileProvider . directive ( 'elementDirective' , function ( ) {
@@ -200,7 +215,7 @@ describe('ngRef', function() {
200
215
return {
201
216
restrict : 'A' ,
202
217
controller : function ( ) {
203
- attrDirective2Controller = this ;
218
+ attrDirective1Controller = this ;
204
219
}
205
220
} ;
206
221
} ) ;
@@ -221,7 +236,7 @@ describe('ngRef', function() {
221
236
'ng-ref="myController"' +
222
237
'ng-ref-read="$element"></element-directive>' ) ( $rootScope ) ;
223
238
224
- expect ( $rootScope . myController ) . toBe ( attrDirective2Controller ) ;
239
+ expect ( $rootScope . myController ) . toBe ( attrDirective1Controller ) ;
225
240
} ) ;
226
241
} ) ;
227
242
0 commit comments