Skip to content

Commit 83a6b15

Browse files
jbedardpetebacondarwin
authored andcommitted
refactor($compile): move setting of controller data to single location
Closes angular#13421
1 parent 9264cef commit 83a6b15

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
@@ -2421,12 +2421,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24212421
}
24222422
}
24232423

2424-
// Initialize bindToController bindings
2424+
// Initialize controllers
24252425
for (var name in elementControllers) {
24262426
var controllerDirective = controllerDirectives[name];
24272427
var controller = elementControllers[name];
24282428
var bindings = controllerDirective.$$bindings.bindToController;
24292429

2430+
// Initialize bindToController bindings
24302431
if (controller.identifier && bindings) {
24312432
controller.bindingInfo =
24322433
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
@@ -2439,11 +2440,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
24392440
// If the controller constructor has a return value, overwrite the instance
24402441
// from setupControllers
24412442
controller.instance = controllerResult;
2442-
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24432443
controller.bindingInfo.removeWatches && controller.bindingInfo.removeWatches();
24442444
controller.bindingInfo =
24452445
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
24462446
}
2447+
2448+
// Store controllers on the $element data
2449+
// For transclude comment nodes this will be a noop and will be done at transclusion time
2450+
$element.data('$' + controllerDirective.name + 'Controller', controllerResult);
24472451
}
24482452

24492453
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
@@ -2610,14 +2614,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26102614
controller = attrs[directive.name];
26112615
}
26122616

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

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