Skip to content

Commit

Permalink
Merge branch 'dgsmith2-oninit-hook'
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Mar 5, 2016
2 parents d3106c8 + 9ecfa49 commit 5d1f50f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ng1/viewDirective.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @module view */ /** for typedoc */
import {extend} from "../common/common";
import {isDefined} from "../common/predicates";
import {isDefined, isFunction} from "../common/predicates";
import {trace} from "../common/trace";
import {ViewConfig} from "../view/view";
import {UIViewData} from "../view/interface";
Expand Down Expand Up @@ -323,6 +323,7 @@ function $ViewDirectiveFill ( $compile, $controller, $interpolate, $injec
scope[controllerAs] = controllerInstance;
scope[controllerAs][resolveAs] = locals;
}
if (isFunction(controllerInstance.$onInit)) controllerInstance.$onInit();
$element.data('$ngControllerController', controllerInstance);
$element.children().data('$ngControllerController', controllerInstance);
}
Expand Down
14 changes: 14 additions & 0 deletions test/viewDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@ 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 5d1f50f

Please sign in to comment.