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