diff --git a/src/directives/viewDirective.ts b/src/directives/viewDirective.ts index feb8a7404..7e47940ee 100644 --- a/src/directives/viewDirective.ts +++ b/src/directives/viewDirective.ts @@ -465,7 +465,7 @@ function registerControllerCallbacks( cfg: Ng1ViewConfig ) { // Call $onInit() ASAP - if (isFunction(controllerInstance.$onInit) && !(cfg.viewDecl.component && hasComponentImpl)) { + if (isFunction(controllerInstance.$onInit) && !((cfg.viewDecl.component || cfg.viewDecl.componentProvider) && hasComponentImpl)) { controllerInstance.$onInit(); } diff --git a/test/viewDirectiveSpec.ts b/test/viewDirectiveSpec.ts index 86de00c93..4a7d9525a 100644 --- a/test/viewDirectiveSpec.ts +++ b/test/viewDirectiveSpec.ts @@ -1334,6 +1334,28 @@ describe('angular 1.5+ style .component()', function() { expect(log).toBe('onInit;'); }); + it('should only call $onInit() once with componentProvider', function() { + $stateProvider.state('route2cmp', { + componentProvider: () => 'ngComponent', + resolve: { + data: function() { + return 'DATA!'; + }, + }, + }); + + const $state = svcs.$state, + $httpBackend = svcs.$httpBackend, + $q = svcs.$q; + + $httpBackend.expectGET('/comp_tpl.html').respond('-{{ $ctrl.data }}-'); + $state.transitionTo('route2cmp'); + $q.flush(); + $httpBackend.flush(); + + expect(log).toBe('onInit;'); + }); + it('should supply resolve data to "<", "=", "@" bindings', function() { $stateProvider.state('bindingtypes', { component: 'bindingTypes',