Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 8349758

Browse files
Daniel SmithFoxandxss
Daniel Smith
authored andcommitted
feat(modal): Call $onInit on controller if defined
Fixes #5472 Closes #5509
1 parent 64e3127 commit 8349758

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/modal/modal.js

+3
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
687687
ctrlInstance.$close = modalScope.$close;
688688
ctrlInstance.$dismiss = modalScope.$dismiss;
689689
angular.extend(ctrlInstance, providedScope);
690+
if (angular.isFunction(ctrlInstance.$onInit)) {
691+
ctrlInstance.$onInit();
692+
}
690693
}
691694

692695
modalScope[modalOptions.controllerAs] = ctrlInstance;

src/modal/test/modal.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,27 @@ describe('$uibModal', function() {
826826
});
827827
expect($document).toHaveModalOpenWithContent('Content from ctrl true bar', 'div');
828828
});
829+
830+
it('should have $onInit called', function() {
831+
var $scope = $rootScope.$new(true);
832+
var $onInit = jasmine.createSpy('$onInit');
833+
$scope.foo = 'bar';
834+
open({
835+
template: '<div>{{test.fromCtrl}} {{test.closeDismissPresent()}} {{test.foo}}</div>',
836+
controller: function($uibModalInstance) {
837+
this.$onInit = $onInit;
838+
this.fromCtrl = 'Content from ctrl';
839+
this.closeDismissPresent = function() {
840+
return angular.isFunction(this.$close) && angular.isFunction(this.$dismiss);
841+
};
842+
},
843+
controllerAs: 'test',
844+
bindToController: true,
845+
scope: $scope
846+
});
847+
expect($document).toHaveModalOpenWithContent('Content from ctrl true bar', 'div');
848+
expect($onInit).toHaveBeenCalled();
849+
});
829850
});
830851

831852
describe('resolve', function() {

0 commit comments

Comments
 (0)