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

Commit 21d148a

Browse files
jbedardpetebacondarwin
authored andcommitted
refactor($compile): move setting of controller data to single location
Closes #13421
1 parent 4c8aeef commit 21d148a

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/ng/compile.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,12 +2434,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24342434
}
24352435
}
24362436

2437-
// Initialize bindToController bindings
2437+
// Initialize controllers
24382438
for (var name in elementControllers) {
24392439
var controllerDirective = controllerDirectives[name];
24402440
var controller = elementControllers[name];
24412441
var bindings = controllerDirective.$$bindings.bindToController;
24422442

2443+
// Initialize bindToController bindings
24432444
if (controller.identifier && bindings) {
24442445
controller.bindingInfo =
24452446
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
@@ -2452,11 +2453,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24522453
// If the controller constructor has a return value, overwrite the instance
24532454
// from setupControllers
24542455
controller.instance = controllerResult;
2455-
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24562456
controller.bindingInfo.removeWatches && controller.bindingInfo.removeWatches();
24572457
controller.bindingInfo =
24582458
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
24592459
}
2460+
2461+
// Store controllers on the $element data
2462+
// For transclude comment nodes this will be a noop and will be done at transclusion time
2463+
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24602464
}
24612465

24622466
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
@@ -2623,14 +2627,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26232627
controller = attrs[directive.name];
26242628
}
26252629

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy