Skip to content

Commit 9ecfa49

Browse files
merge PR #2570
2 parents d3106c8 + c8afc38 commit 9ecfa49

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/ng1/viewDirective.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @module view */ /** for typedoc */
22
import {extend} from "../common/common";
3-
import {isDefined} from "../common/predicates";
3+
import {isDefined, isFunction} from "../common/predicates";
44
import {trace} from "../common/trace";
55
import {ViewConfig} from "../view/view";
66
import {UIViewData} from "../view/interface";
@@ -323,6 +323,7 @@ function $ViewDirectiveFill ( $compile, $controller, $interpolate, $injec
323323
scope[controllerAs] = controllerInstance;
324324
scope[controllerAs][resolveAs] = locals;
325325
}
326+
if (isFunction(controllerInstance.$onInit)) controllerInstance.$onInit();
326327
$element.data('$ngControllerController', controllerInstance);
327328
$element.children().data('$ngControllerController', controllerInstance);
328329
}

test/viewDirectiveSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,20 @@ describe('uiView', function () {
406406
}));
407407
});
408408

409+
it('should call the existing $onInit after instantiating a controller', inject(function ($state, $q) {
410+
var $onInit = jasmine.createSpy();
411+
$stateProvider.state('onInit', {
412+
controller: function() { this.$onInit = $onInit; },
413+
template: "hi",
414+
controllerAs: "vm"
415+
});
416+
elem.append($compile('<div><ui-view></ui-view></div>')(scope));
417+
$state.transitionTo('onInit');
418+
$q.flush();
419+
420+
expect($onInit).toHaveBeenCalled();
421+
}));
422+
409423
describe('play nicely with other directives', function() {
410424
// related to issue #857
411425
it('should work with ngIf', inject(function ($state, $q, $compile) {

0 commit comments

Comments
 (0)