File tree 2 files changed +38
-1
lines changed
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -1997,9 +1997,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1997
1997
for ( i in elementControllers ) {
1998
1998
controller = elementControllers [ i ] ;
1999
1999
var controllerResult = controller ( ) ;
2000
+
2000
2001
if ( controllerResult !== controller . instance ) {
2002
+ // Assign controller return value to the instance
2001
2003
controller . instance = controllerResult ;
2002
- $element . data ( '$' + directive . name + 'Controller' , controllerResult ) ;
2004
+ $element . data ( '$' + i + 'Controller' , controllerResult ) ;
2003
2005
if ( controller === controllerForBindings ) {
2004
2006
// Remove and re-install bindToController bindings
2005
2007
thisLinkFn . $$destroyBindings ( ) ;
Original file line number Diff line number Diff line change @@ -4573,6 +4573,41 @@ describe('$compile', function() {
4573
4573
} ) ;
4574
4574
4575
4575
4576
+ it ( 'should correctly assign controller return values for multiple directives' , function ( ) {
4577
+ var directiveController , otherDirectiveController ;
4578
+ module ( function ( ) {
4579
+
4580
+ directive ( 'myDirective' , function ( log ) {
4581
+ return {
4582
+ scope : true ,
4583
+ controller : function ( $scope ) {
4584
+ return directiveController = {
4585
+ foo : 'bar'
4586
+ } ;
4587
+ }
4588
+ } ;
4589
+ } ) ;
4590
+
4591
+ directive ( 'myOtherDirective' , function ( log ) {
4592
+ return {
4593
+ controller : function ( $scope ) {
4594
+ return otherDirectiveController = {
4595
+ baz : 'luh'
4596
+ } ;
4597
+ }
4598
+ } ;
4599
+ } ) ;
4600
+
4601
+ } ) ;
4602
+
4603
+ inject ( function ( log , $compile , $rootScope ) {
4604
+ element = $compile ( '<my-directive my-other-directive></my-directive>' ) ( $rootScope ) ;
4605
+ expect ( element . data ( '$myDirectiveController' ) ) . toBe ( directiveController ) ;
4606
+ expect ( element . data ( '$myOtherDirectiveController' ) ) . toBe ( otherDirectiveController ) ;
4607
+ } ) ;
4608
+ } ) ;
4609
+
4610
+
4576
4611
it ( 'should get required parent controller' , function ( ) {
4577
4612
module ( function ( ) {
4578
4613
directive ( 'nested' , function ( log ) {
You can’t perform that action at this time.
0 commit comments