File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -1983,9 +1983,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1983
1983
var scopeDirective = newIsolateScopeDirective || newScopeDirective ;
1984
1984
var bindings ;
1985
1985
var controllerForBindings ;
1986
+ var scopeController ;
1986
1987
if ( scopeDirective && elementControllers [ scopeDirective . name ] ) {
1987
1988
bindings = scopeDirective . $$bindings . bindToController ;
1988
- controller = elementControllers [ scopeDirective . name ] ;
1989
+ controller = scopeController = elementControllers [ scopeDirective . name ] ;
1989
1990
1990
1991
if ( controller && controller . identifier && bindings ) {
1991
1992
controllerForBindings = controller ;
@@ -1997,9 +1998,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
1997
1998
for ( i in elementControllers ) {
1998
1999
controller = elementControllers [ i ] ;
1999
2000
var controllerResult = controller ( ) ;
2001
+
2000
2002
if ( controllerResult !== controller . instance ) {
2001
2003
controller . instance = controllerResult ;
2002
- $element . data ( '$' + directive . name + 'Controller' , controllerResult ) ;
2004
+ var name = controller === scopeController ? scopeDirective . name : directive . name ;
2005
+ $element . data ( '$' + name + 'Controller' , controllerResult ) ;
2003
2006
if ( controller === controllerForBindings ) {
2004
2007
// Remove and re-install bindToController bindings
2005
2008
thisLinkFn . $$destroyBindings ( ) ;
Original file line number Diff line number Diff line change @@ -4573,6 +4573,35 @@ describe('$compile', function() {
4573
4573
} ) ;
4574
4574
4575
4575
4576
+ it ( 'should not confuse ngController and directive controller' , function ( ) {
4577
+ var ngController , directiveController ;
4578
+ module ( function ( $controllerProvider ) {
4579
+ $controllerProvider . register ( 'myCtrl' , function ( ) {
4580
+ return ngController = {
4581
+ foo : 'bar'
4582
+ } ;
4583
+ } ) ;
4584
+
4585
+ directive ( 'myDirective' , function ( log ) {
4586
+ return {
4587
+ controller : function ( $scope ) {
4588
+ return directiveController = {
4589
+ baz : 'val'
4590
+ } ;
4591
+ }
4592
+ } ;
4593
+ } ) ;
4594
+
4595
+ } ) ;
4596
+
4597
+ inject ( function ( log , $compile , $rootScope ) {
4598
+ element = $compile ( '<my-directive ng-controller="myCtrl"></my-directive>' ) ( $rootScope ) ;
4599
+ expect ( element . data ( '$ngControllerController' ) ) . toBe ( ngController ) ;
4600
+ expect ( element . data ( '$myDirectiveController' ) ) . toBe ( directiveController ) ;
4601
+ } ) ;
4602
+ } ) ;
4603
+
4604
+
4576
4605
it ( 'should get required parent controller' , function ( ) {
4577
4606
module ( function ( ) {
4578
4607
directive ( 'nested' , function ( log ) {
You can’t perform that action at this time.
0 commit comments