I have a few custom directives which are basically designed for .
And I have a custom component
There
You can make every directive provide itself like it is done with ControlValueAccessor
or validators
export const MY_DIRECTIVES = new InjectionToken<any>('MyDirectives');
export const MY_DIRECTIVE1: Provider = {
provide: MY_DIRECTIVES,
useExisting: forwardRef(() => MyDirective1),
multi: true
};
@Directive({
selector: '....',
providers: [MY_DIRECTIVE1]
})
class MyDirective1 {}
and then in your input component
constructor(@Optional() @Self() @Inject(MY_DIRECTIVES) private myDirectives: any[]) {
console.log(myDirectives);
}
In the constructor of the directive you can do some like.
constructor(
@Attribute('attributeName') private attributeUno:String,
private element:ElementRef
) {
console.log(this.attributeUno);
}