I am facing a strange issue with dynamic component loading in Angular. I have set up a form stepper with 5 steps, each step being a separate component that is injected when necessary.
class CreateComponent {
// List of components to be injected
private _ContainerContractComponent = [
ContractCivilStatusComponent,
ContractLegalResponsableComponent,
ContractBulletinComponent,
ContractPaymentComponent,
ContractSocialSecurityComponent
];
// List of variables to be injected
private _currentStudent: StudentInterface;
private _candidature: CandidatureInterface;
private _childObserver: Subject<any> = new Subject();
// My current step (numberBetween<1,5>)
private _stepperStep: number;
// Function for loading the contract part component
displayContractPartComponent() {
let componentFactory = this._componentFactoryResolver.resolveComponentFactory(
this._ContainerContractComponent[this._stepperStep - 1]
);
this.dynamicComponentContainer.clear();
let componentRef = this.dynamicComponentContainer.createComponent(componentFactory);
componentRef.instance.candidature = this._candidature;
componentRef.instance.student = this._currentStudent;
componentRef.instance.childObserver = this._childObserver;
}
}
I pass three variables (candidature, student, childObserver) to each loaded component.
Everything was working fine until this morning, when suddenly I started getting this compiler error:
Error in CreateComponent: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'ContractBulletinComponent' is not a valid type argument because it is not a supertype of candidate 'ContractCivilStatusComponent'.
Property '_model' is missing in type 'ContractCivilStatusComponent'.
This error message seems to change with each compilation round and even the name of the component mentioned (such as 'ContractBulletinComponent') varies.
I have been researching all morning but can't figure out where the problem might be coming from. Any help would be greatly appreciated.