Following is the directive example given on Angular documentation for attribute directive https://angular.io/guide/attribute-directives
import { Directive, ElementRef, Input } from '@angular/core';
@Directive({ selector: '[myHighlight]' })
export class HighlightDirective {
constructor(el: ElementRef) {
el.nativeElement.style.backgroundColor = 'yellow';
}
}
Just below it they explain it with following text
- The import statement specifies symbols from the Angular core:
- Directive provides the functionality of the @Directive decorator.
- ElementRef injects into the directive's constructor so the code can access the DOM element.
- Input allows data to flow from the binding expression into the directive.
I am not clear with the fourth point, they say input allows data to flow from binding expression into directive, but in the class no where the Input is used, then how could Angular use it, because previously I read on NgModule documentation, that the import statement on top is not related to Angular
so my understanding is whenever Angular encounters attribute directive, it will create an object using the class HighlightDirective, but since it does not have any reference to Input, how can it get the data flow from binding expression
so in my understanding since we are not accessing data here, we do not need to import Input module at top