Skip to content

Commit

Permalink
Merge pull request #188 from gund/fix-null-comp-injector
Browse files Browse the repository at this point in the history
[Fix] Make sure no errors thrown when component injector is not available
  • Loading branch information
gund authored Oct 16, 2018
2 parents fd99cb8 + 4a0cac2 commit fd3730a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/dynamic/dynamic.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ describe('Directive: Dynamic', () => {
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should NOT throw if component injector is null', () => {
injectorComp.component = null;
expect(() => fixture.detectChanges()).not.toThrow();
});

it('should call `ngOnChanges` once when inputs and component updated', () => {
fixture.detectChanges();
injectorComp.component.ngOnChanges.mockReset();
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic/io.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class IoService implements OnDestroy {
}

private get _componentInst() {
return this._compRef.instance;
return this._compRef ? this._compRef.instance : null;
}

private get _componentInstChanged(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/test/component-injector.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export class ComponentInjectorComponent implements ComponentInjector {
component = new MockedInjectedComponent();

get componentRef(): ComponentRef<ComponentInjectorComponent> {
return {
return this.component ? {
instance: this.component,
} as any;
} as any : null;
}
}

Expand Down

0 comments on commit fd3730a

Please sign in to comment.