Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d87c424

Browse files
committed
review comments
1 parent 20d35f9 commit d87c424

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/ng/directive/ngRef.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ var ngRefMinErr = minErr('ngRef');
244244

245245
var ngRefDirective = ['$parse', function($parse) {
246246
return {
247-
priority: -1,
247+
priority: -1, // Needed for compatibility with transclusion
248248
restrict: 'A',
249249
compile: function(tElement, tAttrs) {
250250
// Get the expected controller name, converts <data-some-thing> into "someThing"
@@ -258,35 +258,34 @@ var ngRefDirective = ['$parse', function($parse) {
258258

259259
return function(scope, element, attrs) {
260260
var refValue;
261-
var controller;
262261

263-
if ('ngRefRead' in attrs) {
262+
if (attrs.hasOwnProperty('ngRefRead')) {
264263
if (attrs.ngRefRead === '$element') {
265264
refValue = element;
266265
} else {
267-
controller = element.data('$' + attrs.ngRefRead + 'Controller');
268-
if (!controller) {
266+
refValue = element.data('$' + attrs.ngRefRead + 'Controller');
267+
268+
if (!refValue) {
269269
throw ngRefMinErr(
270270
'noctrl',
271271
'The controller for ngRefRead="{0}" could not be found on ngRef="{1}"',
272272
attrs.ngRefRead,
273273
tAttrs.ngRef
274274
);
275275
}
276-
277276
}
278277
} else {
279-
controller = element.data('$' + controllerName + 'Controller');
278+
refValue = element.data('$' + controllerName + 'Controller');
280279
}
281280

282-
refValue = refValue || controller || element;
281+
refValue = refValue || element;
283282

284283
setter(scope, refValue);
285284

286285
// when the element is removed, remove it (nullify it)
287286
element.on('$destroy', function() {
288287
// 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
290289
if (getter(scope) === refValue) {
291290
setter(scope, null);
292291
}

0 commit comments

Comments
 (0)