30 lines
598 B
TypeScript
Raw Normal View History

2016-03-26 12:18:13 -04:00
// #docplaster
// #docregion
2016-06-13 00:41:33 +02:00
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
2016-03-26 12:18:13 -04:00
@Directive({
2016-06-13 00:41:33 +02:00
selector: '[myHighlight]'
2016-03-26 12:18:13 -04:00
})
export class HighlightDirective {
@Input('myHighlight') highlightColor: string;
private el: HTMLElement;
2016-03-26 12:18:13 -04:00
constructor(el: ElementRef) {
this.el = el.nativeElement;
2016-03-26 12:18:13 -04:00
}
2016-06-13 00:41:33 +02:00
@HostListener('mouseenter') onMouseEnter() {
this.highlight(this.highlightColor || 'cyan');
}
@HostListener('mouseleave') onMouseLeave() {
this.highlight(null);
}
2016-03-26 12:18:13 -04:00
private highlight(color: string) {
this.el.style.backgroundColor = color;
2016-03-26 12:18:13 -04:00
}
}