Skip to content

Commit

Permalink
feat(uiView): Fire the $onInit hook
Browse files Browse the repository at this point in the history
After instantiating the controller, will fire its $onInit if defined.

Closes #2559
  • Loading branch information
Daniel Smith authored and christopherthielen committed Mar 5, 2016
1 parent a928783 commit b090ca0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ function $ViewDirectiveFill ( $compile, $controller, $state, $interpolate
scope[locals.$$controllerAs] = controller;
scope[locals.$$controllerAs][locals.$$resolveAs] = resolveData;
}
if (isFunction(controller.$onInit)) controller.$onInit();
$element.data('$ngControllerController', controller);
$element.children().data('$ngControllerController', controller);
}
Expand Down
16 changes: 16 additions & 0 deletions test/viewDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,22 @@ describe('uiView', function () {
}));
});

it('should call the existing $onInit after instantiating a controller', inject(function ($state, $q) {
var $onInit = jasmine.createSpy();
$stateProvider.state('onInit', {
controller: function () {
this.$onInit = $onInit;
},
template: "hi",
controllerAs: "vm"
});
elem.append($compile('<div><ui-view></ui-view></div>')(scope));
$state.transitionTo('onInit');
$q.flush();

expect($onInit).toHaveBeenCalled();
}));

describe('play nicely with other directives', function() {
// related to issue #857
it('should work with ngIf', inject(function ($state, $q, $compile) {
Expand Down

0 comments on commit b090ca0

Please sign in to comment.