When working on my Angular application:
If a Component utilizes an Input that is defined in its immediate parent (abstract) class, everything runs smoothly.
However, if a Component uses an Input that is declared in a parent class located two levels above (abstract), issues arise during the execution of
ng build
orng serve
.
For instance, there are 4 classes involved:
export abstract class AbstractAComponent {
@Input() myInput: string;
}
export abstract class AbstractBComponent extends AbstractAComponent {}
@Component({
selector: 'app-one',
templateUrl: './one.component.html',
styleUrls: ['./one.component.scss']
})
export class OneComponent extends AbstractAComponent {}
@Component({
selector: 'app-two',
templateUrl: './two.component.html',
styleUrls: ['./two.component.scss']
})
export class TwoComponent extends AbstractBComponent {}
This is how they are implemented:
<app-one [myInput]="'value 1'"></app-one>
<app-two [myInput]="'value 2'"></app-two>
In summary:
- The declaration @Input() myInput
exists within AbstractAComponent
- OneComponent
directly inherits from AbstractAComponent
- TwoComponent
extends AbstractBComponent
, which further extends AbstractAComponent
Expected outcome:
- both OneComponent
and TwoComponent
should possess @Input() myInput
Current scenario:
- It appears that TwoComponent
is not inheriting @Input() myInput
as expected
This leads to the following error message:
ERROR in src/app/app.component.html:2:10 - error NG8002: Can't bind to 'myInput' since it isn't a known property of 'app-two'.
1. If 'app-two' is an Angular component and it has 'myInput' input, then verify that it is part of this module.
2. If 'app-two' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property, add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.