@@ -244,7 +244,7 @@ var ngRefMinErr = minErr('ngRef');
244
244
245
245
var ngRefDirective = [ '$parse' , function ( $parse ) {
246
246
return {
247
- priority : - 1 ,
247
+ priority : - 1 , // Needed for compatibility with transclusion
248
248
restrict : 'A' ,
249
249
compile : function ( tElement , tAttrs ) {
250
250
// Get the expected controller name, converts <data-some-thing> into "someThing"
@@ -258,35 +258,34 @@ var ngRefDirective = ['$parse', function($parse) {
258
258
259
259
return function ( scope , element , attrs ) {
260
260
var refValue ;
261
- var controller ;
262
261
263
- if ( 'ngRefRead' in attrs ) {
262
+ if ( attrs . hasOwnProperty ( 'ngRefRead' ) ) {
264
263
if ( attrs . ngRefRead === '$element' ) {
265
264
refValue = element ;
266
265
} else {
267
- controller = element . data ( '$' + attrs . ngRefRead + 'Controller' ) ;
268
- if ( ! controller ) {
266
+ refValue = element . data ( '$' + attrs . ngRefRead + 'Controller' ) ;
267
+
268
+ if ( ! refValue ) {
269
269
throw ngRefMinErr (
270
270
'noctrl' ,
271
271
'The controller for ngRefRead="{0}" could not be found on ngRef="{1}"' ,
272
272
attrs . ngRefRead ,
273
273
tAttrs . ngRef
274
274
) ;
275
275
}
276
-
277
276
}
278
277
} else {
279
- controller = element . data ( '$' + controllerName + 'Controller' ) ;
278
+ refValue = element . data ( '$' + controllerName + 'Controller' ) ;
280
279
}
281
280
282
- refValue = refValue || controller || element ;
281
+ refValue = refValue || element ;
283
282
284
283
setter ( scope , refValue ) ;
285
284
286
285
// when the element is removed, remove it (nullify it)
287
286
element . on ( '$destroy' , function ( ) {
288
287
// only remove it if value has not changed,
289
- // carefully because animations (and other procedures) may duplicate elements
288
+ // because animations (and other procedures) may duplicate elements
290
289
if ( getter ( scope ) === refValue ) {
291
290
setter ( scope , null ) ;
292
291
}
0 commit comments