@@ -4219,6 +4219,28 @@ describe('$compile', function() {
4219
4219
} ) ;
4220
4220
4221
4221
4222
+ it ( 'primitive controller return values are ignored' , function ( ) {
4223
+ module ( function ( ) {
4224
+ directive ( 'logControllerProp' , function ( log ) {
4225
+ return {
4226
+ controller : function ( $scope ) {
4227
+ this . foo = 'baz' ; // value *will* be used.
4228
+ return 'bar' ;
4229
+ } ,
4230
+ link : function ( scope , element , attrs , controller ) {
4231
+ log ( controller . foo ) ;
4232
+ }
4233
+ } ;
4234
+ } ) ;
4235
+ } ) ;
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' ) ;
4240
+ } ) ;
4241
+ } ) ;
4242
+
4243
+
4222
4244
it ( 'should get required parent controller' , function ( ) {
4223
4245
module ( function ( ) {
4224
4246
directive ( 'nested' , function ( log ) {
@@ -4238,6 +4260,28 @@ describe('$compile', function() {
4238
4260
} ) ;
4239
4261
4240
4262
4263
+ it ( 'should get explicit return value of required parent controller' , function ( ) {
4264
+ module ( function ( ) {
4265
+ directive ( 'nested' , function ( log ) {
4266
+ return {
4267
+ require : '^^?nested' ,
4268
+ controller : function ( ) {
4269
+ return { foo : 'bar' } ;
4270
+ } ,
4271
+ link : function ( scope , element , attrs , controller ) {
4272
+ log ( ! ! controller && controller . foo ) ;
4273
+ }
4274
+ } ;
4275
+ } ) ;
4276
+ } ) ;
4277
+ inject ( function ( log , $compile , $rootScope ) {
4278
+ element = $compile ( '<div nested><div nested></div></div>' ) ( $rootScope ) ;
4279
+
4280
+ expect ( log ) . toEqual ( 'bar; false' ) ;
4281
+ } ) ;
4282
+ } ) ;
4283
+
4284
+
4241
4285
it ( 'should get required parent controller when the question mark precedes the ^^' , function ( ) {
4242
4286
module ( function ( ) {
4243
4287
directive ( 'nested' , function ( log ) {
@@ -4546,6 +4590,30 @@ describe('$compile', function() {
4546
4590
} ) ;
4547
4591
4548
4592
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
+
4549
4617
it ( 'should support controller alias' , function ( ) {
4550
4618
module ( function ( $controllerProvider ) {
4551
4619
$controllerProvider . register ( 'MainCtrl' , function ( ) {
@@ -5547,6 +5615,41 @@ describe('$compile', function() {
5547
5615
} ) ;
5548
5616
} ) ;
5549
5617
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
+
5550
5653
it ( 'should provide the $transclude controller local as 5th argument to the pre and post-link function' , function ( ) {
5551
5654
var ctrlTransclude , preLinkTransclude , postLinkTransclude ;
5552
5655
module ( function ( ) {
0 commit comments