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

Commit c671125

Browse files
revert: refactor($compile): move setting of controller data to single location
Reverted from commit 21d148a since it caused the Angular Material tabs directive to fail.
1 parent 2b2ec26 commit c671125

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/ng/compile.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,13 +2437,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24372437
}
24382438
}
24392439

2440-
// Initialize controllers
2440+
// Initialize bindToController bindings
24412441
for (var name in elementControllers) {
24422442
var controllerDirective = controllerDirectives[name];
24432443
var controller = elementControllers[name];
24442444
var bindings = controllerDirective.$$bindings.bindToController;
24452445

2446-
// Initialize bindToController bindings
24472446
if (controller.identifier && bindings) {
24482447
controller.bindingInfo =
24492448
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
@@ -2456,14 +2455,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24562455
// If the controller constructor has a return value, overwrite the instance
24572456
// from setupControllers
24582457
controller.instance = controllerResult;
2458+
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24592459
controller.bindingInfo.removeWatches && controller.bindingInfo.removeWatches();
24602460
controller.bindingInfo =
24612461
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
24622462
}
2463-
2464-
// Store controllers on the $element data
2465-
// For transclude comment nodes this will be a noop and will be done at transclusion time
2466-
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24672463
}
24682464

24692465
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
@@ -2630,7 +2626,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26302626
controller = attrs[directive.name];
26312627
}
26322628

2633-
elementControllers[directive.name] = $controller(controller, locals, true, directive.controllerAs);
2629+
var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
2630+
2631+
// For directives with element transclusion the element is a comment.
2632+
// In this case .data will not attach any data.
2633+
// Instead, we save the controllers for the element in a local hash and attach to .data
2634+
// later, once we have the actual element.
2635+
elementControllers[directive.name] = controllerInstance;
2636+
$element.data('$' + directive.name + 'Controller', controllerInstance.instance);
26342637
}
26352638
return elementControllers;
26362639
}

0 commit comments

Comments
 (0)