@@ -669,7 +669,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
669669 }
670670 } ) ;
671671
672- var ctrlInstance , ctrlLocals = { } ;
672+ var ctrlInstance , ctrlInstantiate , ctrlLocals = { } ;
673673
674674 //controllers
675675 if ( modalOptions . controller ) {
@@ -679,18 +679,27 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
679679 ctrlLocals [ key ] = value ;
680680 } ) ;
681681
682- ctrlInstance = $controller ( modalOptions . controller , ctrlLocals ) ;
682+ // the third param will make the controller instantiate later,private api
683+ // @see https://github.com/angular/angular.js/blob/master/src/ng/controller.js#L126
684+ ctrlInstantiate = $controller ( modalOptions . controller , ctrlLocals , true ) ;
683685 if ( modalOptions . controllerAs ) {
686+ ctrlInstance = ctrlInstantiate . instance ;
687+
684688 if ( modalOptions . bindToController ) {
685689 ctrlInstance . $close = modalScope . $close ;
686690 ctrlInstance . $dismiss = modalScope . $dismiss ;
687691 angular . extend ( ctrlInstance , providedScope ) ;
688- if ( angular . isFunction ( ctrlInstance . $onInit ) ) {
689- ctrlInstance . $onInit ( ) ;
690- }
691692 }
692693
694+ ctrlInstance = ctrlInstantiate ( ) ;
695+
693696 modalScope [ modalOptions . controllerAs ] = ctrlInstance ;
697+ } else {
698+ ctrlInstance = ctrlInstantiate ( ) ;
699+ }
700+
701+ if ( angular . isFunction ( ctrlInstance . $onInit ) ) {
702+ ctrlInstance . $onInit ( ) ;
694703 }
695704 }
696705
0 commit comments