diff --git a/src/viewDirective.js b/src/viewDirective.js index e2dca7ce1..e5391b39d 100644 --- a/src/viewDirective.js +++ b/src/viewDirective.js @@ -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); } diff --git a/test/viewDirectiveSpec.js b/test/viewDirectiveSpec.js index c629db74e..a8fceb620 100644 --- a/test/viewDirectiveSpec.js +++ b/test/viewDirectiveSpec.js @@ -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('