@@ -2216,6 +2216,95 @@ describe('$compile', function() {
2216
2216
expect ( asyncCtrlSpy ) . toHaveBeenCalledOnce ( ) ;
2217
2217
} ) ;
2218
2218
} ) ;
2219
+
2220
+
2221
+
2222
+ it ( 'should instantiate controllers in the parent->child order when transluction, templateUrl and replacement ' +
2223
+ 'are in the mix' , function ( ) {
2224
+ // When a child controller is in the transclusion that replaces the parent element that has a directive with
2225
+ // a controller, we should ensure that we first instantiate the parent and only then stuff that comes from the
2226
+ // transclusion.
2227
+ //
2228
+ // The transclusion moves the child controller onto the same element as parent controller so both controllers are
2229
+ // on the same level.
2230
+
2231
+ module ( function ( ) {
2232
+ directive ( 'parentDirective' , function ( ) {
2233
+ return {
2234
+ transclude : true ,
2235
+ replace : true ,
2236
+ templateUrl : 'parentDirective.html' ,
2237
+ controller : function ( log ) { log ( 'parentController' ) ; }
2238
+ } ;
2239
+ } ) ;
2240
+ directive ( 'childDirective' , function ( ) {
2241
+ return {
2242
+ require : '^parentDirective' ,
2243
+ templateUrl : 'childDirective.html' ,
2244
+ controller : function ( log ) { log ( 'childController' ) ; }
2245
+ } ;
2246
+ } ) ;
2247
+ } ) ;
2248
+
2249
+ inject ( function ( $templateCache , log , $compile , $rootScope ) {
2250
+ $templateCache . put ( 'parentDirective.html' , '<div ng-transclude>parentTemplateText;</div>' ) ;
2251
+ $templateCache . put ( 'childDirective.html' , '<span>childTemplateText;</span>' ) ;
2252
+
2253
+ element = $compile ( '<div parent-directive><div child-directive></div>childContentText;</div>' ) ( $rootScope ) ;
2254
+ $rootScope . $apply ( ) ;
2255
+ expect ( log ) . toEqual ( 'parentController; childController' ) ;
2256
+ expect ( element . text ( ) ) . toBe ( 'parentTemplateText;childTemplateText;childContentText;' )
2257
+ } ) ;
2258
+ } ) ;
2259
+
2260
+
2261
+ it ( 'should instantiate controllers in the parent->child->baby order when nested transluction, templateUrl and ' +
2262
+ 'replacement are in the mix' , function ( ) {
2263
+ // similar to the test above, except that we have one more layer of nesting and nested transclusion
2264
+
2265
+ module ( function ( ) {
2266
+ directive ( 'parentDirective' , function ( ) {
2267
+ return {
2268
+ transclude : true ,
2269
+ replace : true ,
2270
+ templateUrl : 'parentDirective.html' ,
2271
+ controller : function ( log ) { log ( 'parentController' ) ; }
2272
+ } ;
2273
+ } ) ;
2274
+ directive ( 'childDirective' , function ( ) {
2275
+ return {
2276
+ require : '^parentDirective' ,
2277
+ transclude : true ,
2278
+ replace : true ,
2279
+ templateUrl : 'childDirective.html' ,
2280
+ controller : function ( log ) { log ( 'childController' ) ; }
2281
+ } ;
2282
+ } ) ;
2283
+ directive ( 'babyDirective' , function ( ) {
2284
+ return {
2285
+ require : '^childDirective' ,
2286
+ templateUrl : 'babyDirective.html' ,
2287
+ controller : function ( log ) { log ( 'babyController' ) ; }
2288
+ } ;
2289
+ } ) ;
2290
+ } ) ;
2291
+
2292
+ inject ( function ( $templateCache , log , $compile , $rootScope ) {
2293
+ $templateCache . put ( 'parentDirective.html' , '<div ng-transclude>parentTemplateText;</div>' ) ;
2294
+ $templateCache . put ( 'childDirective.html' , '<span ng-transclude>childTemplateText;</span>' ) ;
2295
+ $templateCache . put ( 'babyDirective.html' , '<span>babyTemplateText;</span>' ) ;
2296
+
2297
+ element = $compile ( '<div parent-directive>' +
2298
+ '<div child-directive>' +
2299
+ 'childContentText;' +
2300
+ '<div baby-directive>babyContent;</div>' +
2301
+ '</div>' +
2302
+ '</div>' ) ( $rootScope ) ;
2303
+ $rootScope . $apply ( ) ;
2304
+ expect ( log ) . toEqual ( 'parentController; childController; babyController' ) ;
2305
+ expect ( element . text ( ) ) . toBe ( 'parentTemplateText;childTemplateText;childContentText;babyTemplateText;' )
2306
+ } ) ;
2307
+ } ) ;
2219
2308
} ) ;
2220
2309
2221
2310
0 commit comments