Skip to content

Instantly share code, notes, and snippets.

@wKoza
Last active July 25, 2017 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wKoza/c71d67911b5da211dc6f414ddf510b84 to your computer and use it in GitHub Desktop.
Save wKoza/c71d67911b5da211dc6f414ddf510b84 to your computer and use it in GitHub Desktop.
import {Directive, Renderer2, ElementRef, HostListener, Input} from '@angular/core';
@Directive({
selector: '[appHighlight]'
})
export class HighlightDirective {
@Input('appHighlight') highlightColor: string;
private _defaultColor = 'red';
constructor(private _el: ElementRef, private _renderer: Renderer2) {
this._renderer.setStyle(this._el.nativeElement, 'color', this._defaultColor);
}
@HostListener('mouseenter') onMouseEnter() {
this._renderer.setStyle(this._el.nativeElement, 'color', this.highlightColor);
}
@HostListener('mouseleave') onMouseLeave() {
this._renderer.setStyle(this._el.nativeElement, 'color', this._defaultColor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment