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

Commit 0d55298

Browse files
revert: refactor($compile): move setting of controller data to single location
Reverted from commit 83a6b15 since it caused the Angular Material tabs directives to break.
1 parent 56861c0 commit 0d55298

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
@@ -2424,13 +2424,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24242424
}
24252425
}
24262426

2427-
// Initialize controllers
2427+
// Initialize bindToController bindings
24282428
for (var name in elementControllers) {
24292429
var controllerDirective = controllerDirectives[name];
24302430
var controller = elementControllers[name];
24312431
var bindings = controllerDirective.$$bindings.bindToController;
24322432

2433-
// Initialize bindToController bindings
24342433
if (controller.identifier && bindings) {
24352434
controller.bindingInfo =
24362435
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
@@ -2443,14 +2442,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24432442
// If the controller constructor has a return value, overwrite the instance
24442443
// from setupControllers
24452444
controller.instance = controllerResult;
2445+
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24462446
controller.bindingInfo.removeWatches && controller.bindingInfo.removeWatches();
24472447
controller.bindingInfo =
24482448
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
24492449
}
2450-
2451-
// Store controllers on the $element data
2452-
// For transclude comment nodes this will be a noop and will be done at transclusion time
2453-
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24542450
}
24552451

24562452
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
@@ -2617,7 +2613,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26172613
controller = attrs[directive.name];
26182614
}
26192615

2620-
elementControllers[directive.name] = $controller(controller, locals, true, directive.controllerAs);
2616+
var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
2617+
2618+
// For directives with element transclusion the element is a comment.
2619+
// In this case .data will not attach any data.
2620+
// Instead, we save the controllers for the element in a local hash and attach to .data
2621+
// later, once we have the actual element.
2622+
elementControllers[directive.name] = controllerInstance;
2623+
$element.data('$' + directive.name + 'Controller', controllerInstance.instance);
26212624
}
26222625
return elementControllers;
26232626
}

0 commit comments

Comments
 (0)