I have the following components :
@Directive()
export abstract class AbstractControlComponent<T> implements ControlValueAccessor {
...
@Input() warnings: string[] = [];
...
}
@Component({
selector: 'test-input',
templateUrl: './input.component.html',
styleUrls: ['./input.component.scss']
})
export class InputComponent extends AbstractControlComponent<string> {
}
@Component({
selector: 'test-datepicker',
templateUrl: './datepicker.component.html',
styleUrls: ['./datepicker.component.scss']
})
export class DatepickerComponent extends AbstractControlComponent<Date> {
}
and a simple Directive where I would like to change the @Input property ‘warnings’ of my components.
@Directive({
selector: '[validation]',
})
export class ValidationDirective {
constructor(private readonly control: NgControl) {
}
}
I tried to inject the AbstractComponent in the constructor :
constructor(
private readonly control: NgControl,
@Host() readonly component: AbstractControlComponent<any>) {
}
ngOnInit(): void {
this.component.warnings = ['test1', 'test2'];
}
But it gives me an error :
Error: NG0201: No provider for _AbstractControlComponent found in NodeInjector
And I don’t want to inject concrete components as my directive is generic.
Do you know how I can achieve that ?