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

Commit

Permalink
feat(modal): Call $onInit on controller if defined
Browse files Browse the repository at this point in the history
Fixes #5472
Closes #5509
  • Loading branch information
Daniel Smith authored and Foxandxss committed Feb 19, 2016
1 parent 64e3127 commit 8349758
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit 8349758

Please sign in to comment.