diff --git a/src/modal/modal.js b/src/modal/modal.js index 3025e0d136..f591088161 100644 --- a/src/modal/modal.js +++ b/src/modal/modal.js @@ -687,6 +687,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap']) ctrlInstance.$close = modalScope.$close; ctrlInstance.$dismiss = modalScope.$dismiss; angular.extend(ctrlInstance, providedScope); + if (angular.isFunction(ctrlInstance.$onInit)) { + ctrlInstance.$onInit(); + } } modalScope[modalOptions.controllerAs] = ctrlInstance; diff --git a/src/modal/test/modal.spec.js b/src/modal/test/modal.spec.js index fae3a34556..84d22f50ba 100644 --- a/src/modal/test/modal.spec.js +++ b/src/modal/test/modal.spec.js @@ -826,6 +826,27 @@ describe('$uibModal', function() { }); expect($document).toHaveModalOpenWithContent('Content from ctrl true bar', 'div'); }); + + it('should have $onInit called', function() { + var $scope = $rootScope.$new(true); + var $onInit = jasmine.createSpy('$onInit'); + $scope.foo = 'bar'; + open({ + template: '
{{test.fromCtrl}} {{test.closeDismissPresent()}} {{test.foo}}
', + controller: function($uibModalInstance) { + this.$onInit = $onInit; + this.fromCtrl = 'Content from ctrl'; + this.closeDismissPresent = function() { + return angular.isFunction(this.$close) && angular.isFunction(this.$dismiss); + }; + }, + controllerAs: 'test', + bindToController: true, + scope: $scope + }); + expect($document).toHaveModalOpenWithContent('Content from ctrl true bar', 'div'); + expect($onInit).toHaveBeenCalled(); + }); }); describe('resolve', function() {