This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -616,8 +616,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
616
616
samePromise = promiseChain = $q . all ( [ promiseChain ] )
617
617
. then ( resolveWithTemplate , resolveWithTemplate )
618
618
. then ( function resolveSuccess ( tplAndVars ) {
619
+ var providedScope = modalOptions . scope || $rootScope ;
619
620
620
- var modalScope = ( modalOptions . scope || $rootScope ) . $new ( ) ;
621
+ var modalScope = providedScope . $new ( ) ;
621
622
modalScope . $close = modalInstance . close ;
622
623
modalScope . $dismiss = modalInstance . dismiss ;
623
624
@@ -641,7 +642,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
641
642
ctrlInstance = $controller ( modalOptions . controller , ctrlLocals ) ;
642
643
if ( modalOptions . controllerAs ) {
643
644
if ( modalOptions . bindToController ) {
644
- angular . extend ( ctrlInstance , modalScope ) ;
645
+ ctrlInstance . $close = modalScope . $close ;
646
+ ctrlInstance . $dismiss = modalScope . $dismiss ;
647
+ angular . extend ( ctrlInstance , providedScope ) ;
645
648
}
646
649
647
650
modalScope [ modalOptions . controllerAs ] = ctrlInstance ;
Original file line number Diff line number Diff line change @@ -663,11 +663,21 @@ describe('$uibModal', function () {
663
663
} ) ;
664
664
665
665
it ( 'should allow usage of bindToController' , function ( ) {
666
- open ( { template : '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>' , controller : function ( $uibModalInstance ) {
667
- this . fromCtrl = 'Content from ctrl' ;
668
- this . isModalInstance = angular . isObject ( $uibModalInstance ) && angular . isFunction ( $uibModalInstance . close ) ;
669
- } , controllerAs : 'test' , bindToController : true } ) ;
670
- expect ( $document ) . toHaveModalOpenWithContent ( 'Content from ctrl true' , 'div' ) ;
666
+ var $scope = $rootScope . $new ( true ) ;
667
+ $scope . foo = 'bar' ;
668
+ open ( {
669
+ template : '<div>{{test.fromCtrl}} {{test.closeDismissPresent()}} {{test.foo}}</div>' ,
670
+ controller : function ( $uibModalInstance ) {
671
+ this . fromCtrl = 'Content from ctrl' ;
672
+ this . closeDismissPresent = function ( ) {
673
+ return angular . isFunction ( this . $close ) && angular . isFunction ( this . $dismiss ) ;
674
+ } ;
675
+ } ,
676
+ controllerAs : 'test' ,
677
+ bindToController : true ,
678
+ scope : $scope
679
+ } ) ;
680
+ expect ( $document ) . toHaveModalOpenWithContent ( 'Content from ctrl true bar' , 'div' ) ;
671
681
} ) ;
672
682
} ) ;
673
683
You can’t perform that action at this time.
0 commit comments