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

feat(modal): Call $onInit on controller if defined #5509

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div>{{test.fromCtrl}} {{test.closeDismissPresent()}} {{test.foo}}</div>',
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() {
Expand Down