@@ -669,7 +669,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
669
669
}
670
670
} ) ;
671
671
672
- var ctrlInstance , ctrlLocals = { } ;
672
+ var ctrlInstance , ctrlInstantiate , ctrlLocals = { } ;
673
673
674
674
//controllers
675
675
if ( modalOptions . controller ) {
@@ -679,18 +679,27 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
679
679
ctrlLocals [ key ] = value ;
680
680
} ) ;
681
681
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 ) ;
683
685
if ( modalOptions . controllerAs ) {
686
+ ctrlInstance = ctrlInstantiate . instance ;
687
+
684
688
if ( modalOptions . bindToController ) {
685
689
ctrlInstance . $close = modalScope . $close ;
686
690
ctrlInstance . $dismiss = modalScope . $dismiss ;
687
691
angular . extend ( ctrlInstance , providedScope ) ;
688
- if ( angular . isFunction ( ctrlInstance . $onInit ) ) {
689
- ctrlInstance . $onInit ( ) ;
690
- }
691
692
}
692
693
694
+ ctrlInstance = ctrlInstantiate ( ) ;
695
+
693
696
modalScope [ modalOptions . controllerAs ] = ctrlInstance ;
697
+ } else {
698
+ ctrlInstance = ctrlInstantiate ( ) ;
699
+ }
700
+
701
+ if ( angular . isFunction ( ctrlInstance . $onInit ) ) {
702
+ ctrlInstance . $onInit ( ) ;
694
703
}
695
704
}
696
705
0 commit comments