From f087d5ee6cdd2d13e6007d85fded437a9e0f39c9 Mon Sep 17 00:00:00 2001 From: mlnkw Date: Sun, 9 Jun 2019 23:57:30 +0300 Subject: [PATCH 1/2] fix(viewDirective): add check for componentProvider avoid extra trigger for $onInit (fixing #3735) --- src/directives/viewDirective.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); } From f77292861316f6a0417abe8ce6dcf1aed549013e Mon Sep 17 00:00:00 2001 From: mlnkw Date: Mon, 10 Jun 2019 00:24:15 +0300 Subject: [PATCH 2/2] tests(viewDirective): add check for componentProvider check extra trigger for $onInit (#3735) --- test/viewDirectiveSpec.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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',