Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/directives/viewDirective.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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