Skip to content

Commit

Permalink
fix(viewDirective): add check for componentProvider, avoid extra trig…
Browse files Browse the repository at this point in the history
…ger for $onInit (fixing #3735) (#3779)
  • Loading branch information
mlnkw authored and christopherthielen committed Sep 3, 2019
1 parent 74772bd commit c3e87ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/directives/viewDirective.ts
Expand Up @@ -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();
}

Expand Down
22 changes: 22 additions & 0 deletions test/viewDirectiveSpec.ts
Expand Up @@ -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',
Expand Down

0 comments on commit c3e87ad

Please sign in to comment.