This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed
Expand file tree Collapse file tree 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'])
616616 samePromise = promiseChain = $q . all ( [ promiseChain ] )
617617 . then ( resolveWithTemplate , resolveWithTemplate )
618618 . then ( function resolveSuccess ( tplAndVars ) {
619+ var providedScope = modalOptions . scope || $rootScope ;
619620
620- var modalScope = ( modalOptions . scope || $rootScope ) . $new ( ) ;
621+ var modalScope = providedScope . $new ( ) ;
621622 modalScope . $close = modalInstance . close ;
622623 modalScope . $dismiss = modalInstance . dismiss ;
623624
@@ -641,7 +642,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
641642 ctrlInstance = $controller ( modalOptions . controller , ctrlLocals ) ;
642643 if ( modalOptions . controllerAs ) {
643644 if ( modalOptions . bindToController ) {
644- angular . extend ( ctrlInstance , modalScope ) ;
645+ ctrlInstance . $close = modalScope . $close ;
646+ ctrlInstance . $dismiss = modalScope . $dismiss ;
647+ angular . extend ( ctrlInstance , providedScope ) ;
645648 }
646649
647650 modalScope [ modalOptions . controllerAs ] = ctrlInstance ;
Original file line number Diff line number Diff line change @@ -663,11 +663,21 @@ describe('$uibModal', function () {
663663 } ) ;
664664
665665 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' ) ;
671681 } ) ;
672682 } ) ;
673683
You can’t perform that action at this time.
0 commit comments