@@ -4197,7 +4197,7 @@ describe('$compile', function() {
4197
4197
} ) ;
4198
4198
4199
4199
4200
- it ( 'should respect controller return value' , function ( ) {
4200
+ it ( 'should respect explicit return value from controller ' , function ( ) {
4201
4201
module ( function ( ) {
4202
4202
directive ( 'logControllerProp' , function ( log ) {
4203
4203
return {
@@ -4219,65 +4219,123 @@ describe('$compile', function() {
4219
4219
} ) ;
4220
4220
4221
4221
4222
- it ( 'primitive controller return values are ignored ' , function ( ) {
4222
+ it ( 'should get explicit return value of required parent controller ' , function ( ) {
4223
4223
module ( function ( ) {
4224
- directive ( 'logControllerProp ' , function ( log ) {
4224
+ directive ( 'nested ' , function ( log ) {
4225
4225
return {
4226
- controller : function ( $scope ) {
4227
- this . foo = 'baz' ; // value *will* be used.
4228
- return 'bar' ;
4226
+ require : '^^?nested' ,
4227
+ controller : function ( ) {
4228
+ return { foo : 'bar' } ;
4229
4229
} ,
4230
4230
link : function ( scope , element , attrs , controller ) {
4231
- log ( controller . foo ) ;
4231
+ log ( ! ! controller && controller . foo ) ;
4232
4232
}
4233
4233
} ;
4234
4234
} ) ;
4235
4235
} ) ;
4236
4236
inject ( function ( log , $compile , $rootScope ) {
4237
- element = $compile ( '<log-controller-prop></log-controller-prop >' ) ( $rootScope ) ;
4238
- expect ( log ) . toEqual ( 'baz' ) ;
4239
- expect ( element . data ( '$logControllerPropController' ) . foo ) . toEqual ( 'baz ' ) ;
4237
+ element = $compile ( '<div nested><div nested></div></div >' ) ( $rootScope ) ;
4238
+
4239
+ expect ( log ) . toEqual ( 'bar; false ' ) ;
4240
4240
} ) ;
4241
4241
} ) ;
4242
4242
4243
4243
4244
- it ( 'should get required parent controller' , function ( ) {
4244
+ it ( 'should respect explicit controller return value when using controllerAs ' , function ( ) {
4245
4245
module ( function ( ) {
4246
+ directive ( 'main' , function ( ) {
4247
+ return {
4248
+ templateUrl : 'main.html' ,
4249
+ scope : { } ,
4250
+ controller : function ( ) {
4251
+ this . name = 'lucas' ;
4252
+ return { name : 'george' } ;
4253
+ } ,
4254
+ controllerAs : 'mainCtrl'
4255
+ } ;
4256
+ } ) ;
4257
+ } ) ;
4258
+ inject ( function ( $templateCache , $compile , $rootScope ) {
4259
+ $templateCache . put ( 'main.html' , '<span>template:{{mainCtrl.name}}</span>' ) ;
4260
+ element = $compile ( '<main/>' ) ( $rootScope ) ;
4261
+ $rootScope . $apply ( ) ;
4262
+ expect ( element . text ( ) ) . toBe ( 'template:george' ) ;
4263
+ } ) ;
4264
+ } ) ;
4265
+
4266
+
4267
+ it ( 'transcluded children should receive explicit return value of parent controller' , function ( ) {
4268
+ var expectedController ;
4269
+ module ( function ( ) {
4270
+ directive ( 'nester' , valueFn ( {
4271
+ transclude : 'content' ,
4272
+ controller : function ( $transclude ) {
4273
+ this . foo = 'baz' ;
4274
+ expectedController = { transclude :$transclude , foo : 'bar' } ;
4275
+ return expectedController ;
4276
+ } ,
4277
+ link : function ( scope , el , attr , ctrl ) {
4278
+ ctrl . transclude ( cloneAttach ) ;
4279
+ function cloneAttach ( clone ) {
4280
+ el . append ( clone ) ;
4281
+ }
4282
+ }
4283
+ } ) ) ;
4246
4284
directive ( 'nested' , function ( log ) {
4247
4285
return {
4248
- require : '^^?nested' ,
4249
- controller : function ( $scope ) { } ,
4286
+ require : '^^nester' ,
4250
4287
link : function ( scope , element , attrs , controller ) {
4251
- log ( ! ! controller ) ;
4288
+ expect ( controller ) . toBe ( expectedController ) ;
4289
+ log ( 'done' ) ;
4290
+ }
4291
+ } ;
4292
+ } ) ;
4293
+ } ) ;
4294
+ inject ( function ( log , $compile ) {
4295
+ element = $compile ( '<div nester><div nested></div></div>' ) ( $rootScope ) ;
4296
+ $rootScope . $apply ( ) ;
4297
+ expect ( log ) . toEqual ( 'done' ) ;
4298
+ } ) ;
4299
+ } ) ;
4300
+
4301
+
4302
+ it ( 'explicit controller return values are ignored if they are primitives' , function ( ) {
4303
+ module ( function ( ) {
4304
+ directive ( 'logControllerProp' , function ( log ) {
4305
+ return {
4306
+ controller : function ( $scope ) {
4307
+ this . foo = 'baz' ; // value *will* be used.
4308
+ return 'bar' ;
4309
+ } ,
4310
+ link : function ( scope , element , attrs , controller ) {
4311
+ log ( controller . foo ) ;
4252
4312
}
4253
4313
} ;
4254
4314
} ) ;
4255
4315
} ) ;
4256
4316
inject ( function ( log , $compile , $rootScope ) {
4257
- element = $compile ( '<div nested><div nested></div></div>' ) ( $rootScope ) ;
4258
- expect ( log ) . toEqual ( 'true; false' ) ;
4317
+ element = $compile ( '<log-controller-prop></log-controller-prop>' ) ( $rootScope ) ;
4318
+ expect ( log ) . toEqual ( 'baz' ) ;
4319
+ expect ( element . data ( '$logControllerPropController' ) . foo ) . toEqual ( 'baz' ) ;
4259
4320
} ) ;
4260
4321
} ) ;
4261
4322
4262
4323
4263
- it ( 'should get explicit return value of required parent controller' , function ( ) {
4324
+ it ( 'should get required parent controller' , function ( ) {
4264
4325
module ( function ( ) {
4265
4326
directive ( 'nested' , function ( log ) {
4266
4327
return {
4267
4328
require : '^^?nested' ,
4268
- controller : function ( ) {
4269
- return { foo : 'bar' } ;
4270
- } ,
4329
+ controller : function ( $scope ) { } ,
4271
4330
link : function ( scope , element , attrs , controller ) {
4272
- log ( ! ! controller && controller . foo ) ;
4331
+ log ( ! ! controller ) ;
4273
4332
}
4274
4333
} ;
4275
4334
} ) ;
4276
4335
} ) ;
4277
4336
inject ( function ( log , $compile , $rootScope ) {
4278
4337
element = $compile ( '<div nested><div nested></div></div>' ) ( $rootScope ) ;
4279
-
4280
- expect ( log ) . toEqual ( 'bar; false' ) ;
4338
+ expect ( log ) . toEqual ( 'true; false' ) ;
4281
4339
} ) ;
4282
4340
} ) ;
4283
4341
@@ -4590,30 +4648,6 @@ describe('$compile', function() {
4590
4648
} ) ;
4591
4649
4592
4650
4593
- it ( 'should respect explicit controller return value when using controllerAs' , function ( ) {
4594
- module ( function ( ) {
4595
- directive ( 'main' , function ( ) {
4596
- return {
4597
- templateUrl : 'main.html' ,
4598
- transclude : true ,
4599
- scope : { } ,
4600
- controller : function ( ) {
4601
- this . name = 'lucas' ;
4602
- return { name : 'george' } ;
4603
- } ,
4604
- controllerAs : 'mainCtrl'
4605
- } ;
4606
- } ) ;
4607
- } ) ;
4608
- inject ( function ( $templateCache , $compile , $rootScope ) {
4609
- $templateCache . put ( 'main.html' , '<span>template:{{mainCtrl.name}} <div ng-transclude></div></span>' ) ;
4610
- element = $compile ( '<div main>transclude:{{mainCtrl.name}}</div>' ) ( $rootScope ) ;
4611
- $rootScope . $apply ( ) ;
4612
- expect ( element . text ( ) ) . toBe ( 'template:george transclude:' ) ;
4613
- } ) ;
4614
- } ) ;
4615
-
4616
-
4617
4651
it ( 'should support controller alias' , function ( ) {
4618
4652
module ( function ( $controllerProvider ) {
4619
4653
$controllerProvider . register ( 'MainCtrl' , function ( ) {
@@ -5615,40 +5649,6 @@ describe('$compile', function() {
5615
5649
} ) ;
5616
5650
} ) ;
5617
5651
5618
- it ( 'should copy the explicit return value to all clones' , function ( ) {
5619
- module ( function ( ) {
5620
- directive ( 'makeThree' , valueFn ( {
5621
- transclude : 'content' ,
5622
- controller : function ( $transclude ) {
5623
- this . foo = 'baz' ;
5624
- return { transclude :$transclude , foo : 'bar' } ;
5625
- } ,
5626
- link : function ( scope , el , attr , ctrl ) {
5627
- ctrl . transclude ( cloneAttach ) ;
5628
- ctrl . transclude ( cloneAttach ) ;
5629
- ctrl . transclude ( cloneAttach ) ;
5630
-
5631
- function cloneAttach ( clone ) {
5632
- el . append ( clone ) ;
5633
- }
5634
- }
5635
- } ) ) ;
5636
-
5637
- directive ( 'nested' , function ( log ) {
5638
- return {
5639
- require : '^^makeThree' ,
5640
- link : function ( scope , element , attrs , controller ) {
5641
- log ( controller . foo ) ;
5642
- }
5643
- } ;
5644
- } ) ;
5645
- } ) ;
5646
- inject ( function ( log , $compile ) {
5647
- element = $compile ( '<div make-three><div nested></div></div>' ) ( $rootScope ) ;
5648
- $rootScope . $apply ( ) ;
5649
- expect ( log ) . toEqual ( 'bar; bar; bar' ) ;
5650
- } ) ;
5651
- } ) ;
5652
5652
5653
5653
it ( 'should provide the $transclude controller local as 5th argument to the pre and post-link function' , function ( ) {
5654
5654
var ctrlTransclude , preLinkTransclude , postLinkTransclude ;
0 commit comments