diff --git a/src/modal/modal.js b/src/modal/modal.js index f0b82a4fd2..804e208dd3 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -702,23 +702,16 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap', 'ui.bootstrap.p // the third param will make the controller instantiate later,private api // @see https://github.com/angular/angular.js/blob/master/src/ng/controller.js#L126 - ctrlInstantiate = $controller(modalOptions.controller, ctrlLocals, true); - if (modalOptions.controllerAs) { + ctrlInstantiate = $controller(modalOptions.controller, ctrlLocals, true, modalOptions.controllerAs); + if (modalOptions.controllerAs && modalOptions.bindToController) { ctrlInstance = ctrlInstantiate.instance; - - if (modalOptions.bindToController) { - ctrlInstance.$close = modalScope.$close; - ctrlInstance.$dismiss = modalScope.$dismiss; - angular.extend(ctrlInstance, providedScope); - } - - ctrlInstance = ctrlInstantiate(); - - modalScope[modalOptions.controllerAs] = ctrlInstance; - } else { - ctrlInstance = ctrlInstantiate(); + ctrlInstance.$close = modalScope.$close; + ctrlInstance.$dismiss = modalScope.$dismiss; + angular.extend(ctrlInstance, providedScope); } + ctrlInstance = ctrlInstantiate(); + if (angular.isFunction(ctrlInstance.$onInit)) { ctrlInstance.$onInit(); }