@@ -2319,12 +2319,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2319
2319
}
2320
2320
}
2321
2321
2322
- // Initialize bindToController bindings
2322
+ // Initialize controllers
2323
2323
for ( var name in elementControllers ) {
2324
2324
var controllerDirective = controllerDirectives [ name ] ;
2325
2325
var controller = elementControllers [ name ] ;
2326
2326
var bindings = controllerDirective . $$bindings . bindToController ;
2327
2327
2328
+ // Initialize bindToController bindings
2328
2329
if ( controller . identifier && bindings ) {
2329
2330
removeControllerBindingWatches =
2330
2331
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
@@ -2335,11 +2336,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2335
2336
// If the controller constructor has a return value, overwrite the instance
2336
2337
// from setupControllers
2337
2338
controller . instance = controllerResult ;
2338
- $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2339
2339
removeControllerBindingWatches && removeControllerBindingWatches ( ) ;
2340
2340
removeControllerBindingWatches =
2341
2341
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2342
2342
}
2343
+
2344
+ // Store controllers on the $element data
2345
+ // For transclude comment nodes this will be a noop and will be done at transclusion time
2346
+ $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2343
2347
}
2344
2348
2345
2349
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
@@ -2489,14 +2493,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2489
2493
controller = attrs [ directive . name ] ;
2490
2494
}
2491
2495
2492
- var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
2493
-
2494
- // For directives with element transclusion the element is a comment.
2495
- // In this case .data will not attach any data.
2496
- // Instead, we save the controllers for the element in a local hash and attach to .data
2497
- // later, once we have the actual element.
2498
- elementControllers [ directive . name ] = controllerInstance ;
2499
- $element . data ( '$' + directive . name + 'Controller' , controllerInstance . instance ) ;
2496
+ elementControllers [ directive . name ] = $controller ( controller , locals , true , directive . controllerAs ) ;
2500
2497
}
2501
2498
return elementControllers ;
2502
2499
}
0 commit comments