I am learning attribute directives in Angular 2. When using @Input alias in attribute directives, It will not work, why?
component
<p appHighlight = "color">Hightlight Me</p>
directive
export class HighlightDirective {
@Input('appHighlight') highlightcolor: string;
constructor(
// ElementRef is a service that grants direct access to the DOM element through its nativeElement property.
private el: ElementRef
) {
// el.nativeElement.style.backgroundColor = 'yellow';
}
// @HostListener decorator lets you subscribe to events of the DOM element that hosts an attribute directive
@HostListener('mouseenter') onMouseEnter() {
this.highlight(this.highlightcolor || 'red');
}
@HostListener('mouseleave') onmouseleave() {
this.highlight(null);
};
private highlight(color: string) {
this.el.nativeElement.style.backgroundColor = color;
}
}