@@ -5338,7 +5338,7 @@ describe('$compile', function() {
5338
5338
} ) ;
5339
5339
} ) ;
5340
5340
5341
- it ( 'should bind the required controllers to the directive controller, if provided as an object' , function ( ) {
5341
+ it ( 'should bind the required controllers to the directive controller, if provided as an object and bindToController is truthy ' , function ( ) {
5342
5342
var parentController , siblingController ;
5343
5343
5344
5344
function ParentController ( ) { this . name = 'Parent' ; }
@@ -5355,8 +5355,11 @@ describe('$compile', function() {
5355
5355
return {
5356
5356
restrict : 'E' ,
5357
5357
scope : { } ,
5358
+ controllerAs : '$ctrl' ,
5358
5359
require : { container : '^parent' , friend : 'sibling' } ,
5359
- controller : MeController
5360
+ bindToController : true ,
5361
+ controller : MeController ,
5362
+ controllerAs : '$ctrl'
5360
5363
} ;
5361
5364
} )
5362
5365
. directive ( 'parent' , function ( ) {
@@ -5381,6 +5384,50 @@ describe('$compile', function() {
5381
5384
} ) ;
5382
5385
} ) ;
5383
5386
5387
+
5388
+ it ( 'should not bind required controllers bindToController is falsy' , function ( ) {
5389
+ var parentController , siblingController ;
5390
+
5391
+ function ParentController ( ) { this . name = 'Parent' ; }
5392
+ function SiblingController ( ) { this . name = 'Sibling' ; }
5393
+ function MeController ( ) { this . name = 'Me' ; }
5394
+ MeController . prototype . $onInit = function ( ) {
5395
+ parentController = this . container ;
5396
+ siblingController = this . friend ;
5397
+ } ;
5398
+ spyOn ( MeController . prototype , '$onInit' ) . andCallThrough ( ) ;
5399
+
5400
+ angular . module ( 'my' , [ ] )
5401
+ . directive ( 'me' , function ( ) {
5402
+ return {
5403
+ restrict : 'E' ,
5404
+ scope : { } ,
5405
+ require : { container : '^parent' , friend : 'sibling' } ,
5406
+ controller : MeController
5407
+ } ;
5408
+ } )
5409
+ . directive ( 'parent' , function ( ) {
5410
+ return {
5411
+ restrict : 'E' ,
5412
+ scope : { } ,
5413
+ controller : ParentController
5414
+ } ;
5415
+ } )
5416
+ . directive ( 'sibling' , function ( ) {
5417
+ return {
5418
+ controller : SiblingController
5419
+ } ;
5420
+ } ) ;
5421
+
5422
+ module ( 'my' ) ;
5423
+ inject ( function ( $compile , $rootScope , meDirective ) {
5424
+ element = $compile ( '<parent><me sibling></me></parent>' ) ( $rootScope ) ;
5425
+ expect ( MeController . prototype . $onInit ) . toHaveBeenCalled ( ) ;
5426
+ expect ( parentController ) . toBeUndefined ( ) ;
5427
+ expect ( siblingController ) . toBeUndefined ( ) ;
5428
+ } ) ;
5429
+ } ) ;
5430
+
5384
5431
it ( 'should bind required controllers to controller that has an explicit constructor return value' , function ( ) {
5385
5432
var parentController , siblingController , meController ;
5386
5433
@@ -5404,7 +5451,9 @@ describe('$compile', function() {
5404
5451
restrict : 'E' ,
5405
5452
scope : { } ,
5406
5453
require : { container : '^parent' , friend : 'sibling' } ,
5407
- controller : MeController
5454
+ bindToController : true ,
5455
+ controller : MeController ,
5456
+ controllerAs : '$ctrl'
5408
5457
} ;
5409
5458
} )
5410
5459
. directive ( 'parent' , function ( ) {
@@ -5453,7 +5502,9 @@ describe('$compile', function() {
5453
5502
restrict : 'E' ,
5454
5503
scope : { } ,
5455
5504
require : { container : '^parent' , friend : 'sibling' } ,
5456
- controller : MeController
5505
+ bindToController : true ,
5506
+ controller : MeController ,
5507
+ controllerAs : '$ctrl'
5457
5508
} ;
5458
5509
} )
5459
5510
. directive ( 'parent' , function ( ) {
0 commit comments