This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -354,7 +354,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
354354 modalScope . $close = modalInstance . close ;
355355 modalScope . $dismiss = modalInstance . dismiss ;
356356
357- var ctrlLocals = { } ;
357+ var ctrlInstance , ctrlLocals = { } ;
358358 var resolveIter = 1 ;
359359
360360 //controllers
@@ -365,7 +365,10 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.transition'])
365365 ctrlLocals [ key ] = tplAndVars [ resolveIter ++ ] ;
366366 } ) ;
367367
368- $controller ( modalOptions . controllerAs ? modalOptions . controller + ' as ' + modalOptions . controllerAs : modalOptions . controller , ctrlLocals ) ;
368+ ctrlInstance = $controller ( modalOptions . controller , ctrlLocals ) ;
369+ if ( modalOptions . controller ) {
370+ modalScope [ modalOptions . controllerAs ] = ctrlInstance ;
371+ }
369372 }
370373
371374 $modalStack . open ( modalInstance , {
Original file line number Diff line number Diff line change @@ -313,6 +313,14 @@ describe('$modal', function () {
313313 open ( { template : '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>' , controller : 'TestCtrl' , controllerAs : 'test' } ) ;
314314 expect ( $document ) . toHaveModalOpenWithContent ( 'Content from ctrl true' , 'div' ) ;
315315 } ) ;
316+
317+ it ( 'should allow defining in-place controller-as controllers' , function ( ) {
318+ open ( { template : '<div>{{test.fromCtrl}} {{test.isModalInstance}}</div>' , controller : function ( $modalInstance ) {
319+ this . fromCtrl = 'Content from ctrl' ;
320+ this . isModalInstance = angular . isObject ( $modalInstance ) && angular . isFunction ( $modalInstance . close ) ;
321+ } , controllerAs : 'test' } ) ;
322+ expect ( $document ) . toHaveModalOpenWithContent ( 'Content from ctrl true' , 'div' ) ;
323+ } ) ;
316324 } ) ;
317325
318326 describe ( 'resolve' , function ( ) {
You can’t perform that action at this time.
0 commit comments