Skip to content

Commit

Permalink
fix for angular#11343 - bindToController for multiple directives
Browse files Browse the repository at this point in the history
  • Loading branch information
jtorbicki committed Mar 17, 2015
1 parent 170ff9a commit 551adec
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,26 +1970,25 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
if (elementControllers) {
// Initialize bindToController bindings for new/isolate scopes
var scopeDirective = newIsolateScopeDirective || newScopeDirective;
var bindings;
var controllerForBindings;
if (scopeDirective && elementControllers[scopeDirective.name]) {
bindings = scopeDirective.$$bindings.bindToController;
controller = elementControllers[scopeDirective.name];

if (controller && controller.identifier && bindings) {
controllerForBindings = controller;
thisLinkFn.$$destroyBindings =
initializeDirectiveBindings(scope, attrs, controller.instance,
bindings, scopeDirective);
}
}
for (i in elementControllers) {
var scopeDirective = newIsolateScopeDirective || controllerDirectives[i];
var bindings;
var controllerForBindings;
if (scopeDirective && elementControllers[scopeDirective.name]) {
bindings = scopeDirective.$$bindings.bindToController;
controller = elementControllers[scopeDirective.name];
if (controller && controller.identifier && bindings) {
controllerForBindings = controller;
thisLinkFn.$$destroyBindings =
initializeDirectiveBindings(scope, attrs, controller.instance,
bindings, scopeDirective);
}
}
controller = elementControllers[i];
var controllerResult = controller();
if (controllerResult !== controller.instance) {
controller.instance = controllerResult;
$element.data('$' + directive.name + 'Controller', controllerResult);
$element.data('$' + controllerDirectives[i].name + 'Controller', controllerResult);
if (controller === controllerForBindings) {
// Remove and re-install bindToController bindings
thisLinkFn.$$destroyBindings();
Expand Down

0 comments on commit 551adec

Please sign in to comment.