revert: refactor($compile): move setting of controller data to single location

Reverted from commit 83a6b15020 since it caused
the Angular Material tabs directives to break.
This commit is contained in:
Peter Bacon Darwin
2016-04-15 14:06:46 +01:00
parent 56861c0ae9
commit 0d55298b56
+10 -7
View File
@@ -2424,13 +2424,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
}
// Initialize controllers
// Initialize bindToController bindings
for (var name in elementControllers) {
var controllerDirective = controllerDirectives[name];
var controller = elementControllers[name];
var bindings = controllerDirective.$$bindings.bindToController;
// Initialize bindToController bindings
if (controller.identifier && bindings) {
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
@@ -2443,14 +2442,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
// If the controller constructor has a return value, overwrite the instance
// from setupControllers
controller.instance = controllerResult;
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
controller.bindingInfo.removeWatches && controller.bindingInfo.removeWatches();
controller.bindingInfo =
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
}
// Store controllers on the $element data
// For transclude comment nodes this will be a noop and will be done at transclusion time
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
}
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
@@ -2617,7 +2613,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
controller = attrs[directive.name];
}
elementControllers[directive.name] = $controller(controller, locals, true, directive.controllerAs);
var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
// For directives with element transclusion the element is a comment.
// In this case .data will not attach any data.
// Instead, we save the controllers for the element in a local hash and attach to .data
// later, once we have the actual element.
elementControllers[directive.name] = controllerInstance;
$element.data('$' + directive.name + 'Controller', controllerInstance.instance);
}
return elementControllers;
}