-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(attributes): properly resolve constructor types from directives
Since Angular v10 directives no longer contain their constructor arguments in Reflect API and instead NGC stores it in private API. Now library tries to access that private API first to resolve arguments and if it fails - falls back to Reflect API.
- Loading branch information
Showing
11 changed files
with
132 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
projects/ng-dynamic-component/src/lib/dynamic-attributes/dynamic-attributes.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { ComponentOutletInjectorModule } from '../component-injector'; | ||
import { DynamicAttributesDirective } from './dynamic-attributes.directive'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
exports: [DynamicAttributesDirective], | ||
exports: [DynamicAttributesDirective, ComponentOutletInjectorModule], | ||
declarations: [DynamicAttributesDirective], | ||
}) | ||
export class DynamicAttributesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
projects/ng-dynamic-component/src/lib/dynamic-directives/dynamic-directives.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { ComponentOutletInjectorModule } from '../component-injector'; | ||
import { DynamicDirectivesDirective } from './dynamic-directives.directive'; | ||
|
||
@NgModule({ | ||
imports: [CommonModule], | ||
exports: [DynamicDirectivesDirective], | ||
exports: [DynamicDirectivesDirective, ComponentOutletInjectorModule], | ||
declarations: [DynamicDirectivesDirective], | ||
}) | ||
export class DynamicDirectivesModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NgClass } from '@angular/common'; | ||
|
||
import { extractNgParamTypes } from './util'; | ||
import { Component } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
describe('Util', () => { | ||
describe('function extractNgParamTypes()', () => { | ||
it('should return constructor argument types collected by NGC', () => { | ||
const args = extractNgParamTypes(NgClass); | ||
|
||
// To be more flexible just check that there are some arguments | ||
// and do not check for specific types as they are irrelevant and may change | ||
expect(args.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('should return `undefined` for constructor not processed by NGC', () => { | ||
// tslint:disable-next-line: component-selector | ||
@Component({ selector: 'test', template: '' }) | ||
class TestComponent {} | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [TestComponent], | ||
}).compileComponents(); | ||
|
||
const args = extractNgParamTypes(TestComponent); | ||
|
||
expect(args).toBe(undefined); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters