@@ -4197,7 +4197,7 @@ describe('$compile', function() {
41974197 } ) ;
41984198
41994199
4200- it ( 'should respect controller return value' , function ( ) {
4200+ it ( 'should respect explicit return value from controller ' , function ( ) {
42014201 module ( function ( ) {
42024202 directive ( 'logControllerProp' , function ( log ) {
42034203 return {
@@ -4219,65 +4219,123 @@ describe('$compile', function() {
42194219 } ) ;
42204220
42214221
4222- it ( 'primitive controller return values are ignored ' , function ( ) {
4222+ it ( 'should get explicit return value of required parent controller ' , function ( ) {
42234223 module ( function ( ) {
4224- directive ( 'logControllerProp ' , function ( log ) {
4224+ directive ( 'nested ' , function ( log ) {
42254225 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' } ;
42294229 } ,
42304230 link : function ( scope , element , attrs , controller ) {
4231- log ( controller . foo ) ;
4231+ log ( ! ! controller && controller . foo ) ;
42324232 }
42334233 } ;
42344234 } ) ;
42354235 } ) ;
42364236 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 ' ) ;
42404240 } ) ;
42414241 } ) ;
42424242
42434243
4244- it ( 'should get required parent controller' , function ( ) {
4244+ it ( 'should respect explicit controller return value when using controllerAs ' , function ( ) {
42454245 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+ } ) ) ;
42464284 directive ( 'nested' , function ( log ) {
42474285 return {
4248- require : '^^?nested' ,
4249- controller : function ( $scope ) { } ,
4286+ require : '^^nester' ,
42504287 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 ) ;
42524312 }
42534313 } ;
42544314 } ) ;
42554315 } ) ;
42564316 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' ) ;
42594320 } ) ;
42604321 } ) ;
42614322
42624323
4263- it ( 'should get explicit return value of required parent controller' , function ( ) {
4324+ it ( 'should get required parent controller' , function ( ) {
42644325 module ( function ( ) {
42654326 directive ( 'nested' , function ( log ) {
42664327 return {
42674328 require : '^^?nested' ,
4268- controller : function ( ) {
4269- return { foo : 'bar' } ;
4270- } ,
4329+ controller : function ( $scope ) { } ,
42714330 link : function ( scope , element , attrs , controller ) {
4272- log ( ! ! controller && controller . foo ) ;
4331+ log ( ! ! controller ) ;
42734332 }
42744333 } ;
42754334 } ) ;
42764335 } ) ;
42774336 inject ( function ( log , $compile , $rootScope ) {
42784337 element = $compile ( '<div nested><div nested></div></div>' ) ( $rootScope ) ;
4279-
4280- expect ( log ) . toEqual ( 'bar; false' ) ;
4338+ expect ( log ) . toEqual ( 'true; false' ) ;
42814339 } ) ;
42824340 } ) ;
42834341
@@ -4590,30 +4648,6 @@ describe('$compile', function() {
45904648 } ) ;
45914649
45924650
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-
46174651 it ( 'should support controller alias' , function ( ) {
46184652 module ( function ( $controllerProvider ) {
46194653 $controllerProvider . register ( 'MainCtrl' , function ( ) {
@@ -5615,40 +5649,6 @@ describe('$compile', function() {
56155649 } ) ;
56165650 } ) ;
56175651
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- } ) ;
56525652
56535653 it ( 'should provide the $transclude controller local as 5th argument to the pre and post-link function' , function ( ) {
56545654 var ctrlTransclude , preLinkTransclude , postLinkTransclude ;
0 commit comments