This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -197,15 +197,16 @@ var ngRefDirective = function() {
197
197
}
198
198
199
199
return function ( scope , element ) {
200
- // gets the controller of the current element (see jqLiteController for details)
200
+ // gets the controller of the current component or the current DOM element
201
201
var controller = element . data ( '$' + controllerName + 'Controller' ) ;
202
- scope [ symbolName ] = controller ;
202
+ var value = controller || element [ 0 ] ;
203
+ scope [ symbolName ] = value ;
203
204
204
205
// when the element is removed, remove it from the scope assignment (nullify it)
205
206
element . on ( '$destroy' , function ( ) {
206
- // only remove it if controller has not changed,
207
- // because it can happen that animations (and other procedures) may duplicate elements
208
- if ( scope [ symbolName ] === controller ) {
207
+ // only remove it if value has not changed,
208
+ // carefully because animations (and other procedures) may duplicate elements
209
+ if ( scope [ symbolName ] === value ) {
209
210
scope [ symbolName ] = null ;
210
211
}
211
212
} ) ;
Original file line number Diff line number Diff line change @@ -137,6 +137,17 @@ describe('ngRef', function() {
137
137
138
138
} ) ;
139
139
140
+ it ( 'should bind the dom element if no component' , inject ( function ( $compile , $rootScope ) {
141
+ $compile ( '<span ng-ref="mySpan">my text</span>' ) ( $rootScope ) ;
142
+ expect ( $rootScope . mySpan . textContent ) . toBe ( 'my text' ) ;
143
+ } ) ) ;
144
+
145
+ it ( 'should nullify the dom element value if it is destroyed' , inject ( function ( $compile , $rootScope ) {
146
+ var element = $compile ( '<div><span ng-ref="mySpan">my text</span></div>' ) ( $rootScope ) ;
147
+ element . children ( ) . remove ( ) ;
148
+ expect ( $rootScope . mySpan ) . toBe ( null ) ;
149
+ } ) ) ;
150
+
140
151
it ( 'should be compatible with directives on entities with controller' , function ( ) {
141
152
var myDirectiveController ;
142
153
You can’t perform that action at this time.
0 commit comments