@@ -2086,17 +2086,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2086
2086
controller = attrs [ directive . name ] ;
2087
2087
}
2088
2088
2089
- var controllerInstance = $controller ( controller , locals , true , directive . controllerAs ) ;
2090
-
2091
- // For directives with element transclusion the element is a comment,
2092
- // but jQuery .data doesn't support attaching data to comment nodes as it's hard to
2093
- // clean up (http://bugs.jquery.com/ticket/8335).
2094
- // Instead, we save the controllers for the element in a local hash and attach to .data
2095
- // later, once we have the actual element.
2096
- elementControllers [ directive . name ] = controllerInstance ;
2097
- if ( ! hasElementTranscludeDirective ) {
2098
- $element . data ( '$' + directive . name + 'Controller' , controllerInstance . instance ) ;
2099
- }
2089
+ elementControllers [ directive . name ] = $controller ( controller , locals , true , directive . controllerAs ) ;
2100
2090
}
2101
2091
return elementControllers ;
2102
2092
}
@@ -2146,12 +2136,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2146
2136
}
2147
2137
}
2148
2138
2149
- // Initialize bindToController bindings
2139
+ // Initialize controllers
2150
2140
for ( var name in elementControllers ) {
2151
2141
var controllerDirective = controllerDirectives [ name ] ;
2152
2142
var controller = elementControllers [ name ] ;
2153
2143
var bindings = controllerDirective . $$bindings . bindToController ;
2154
2144
2145
+ // Initialize bindToController bindings
2155
2146
if ( controller . identifier && bindings ) {
2156
2147
removeControllerBindingWatches =
2157
2148
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
@@ -2162,11 +2153,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
2162
2153
// If the controller constructor has a return value, overwrite the instance
2163
2154
// from setupControllers
2164
2155
controller . instance = controllerResult ;
2165
- $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2166
2156
removeControllerBindingWatches && removeControllerBindingWatches ( ) ;
2167
2157
removeControllerBindingWatches =
2168
2158
initializeDirectiveBindings ( controllerScope , attrs , controller . instance , bindings , controllerDirective ) ;
2169
2159
}
2160
+
2161
+ // Store controllers on the $element data
2162
+ // For transclude comment nodes this will be a noop and will be done at transclusion time
2163
+ $element . data ( '$' + controllerDirective . name + 'Controller' , controllerResult ) ;
2170
2164
}
2171
2165
2172
2166
// PRELINKING
0 commit comments