2016-06-12 18:41:33 -04:00
|
|
|
/* tslint:disable:no-unused-variable */
|
2015-11-19 19:59:22 -05:00
|
|
|
// #docregion
|
2016-08-22 05:35:22 -04:00
|
|
|
import { Directive, ElementRef, HostListener, Input, Renderer } from '@angular/core';
|
2015-11-19 19:59:22 -05:00
|
|
|
|
|
|
|
@Directive({
|
2016-06-12 18:41:33 -04:00
|
|
|
selector: '[myHighlight]'
|
2015-11-19 19:59:22 -05:00
|
|
|
})
|
|
|
|
|
2015-12-16 22:38:07 -05:00
|
|
|
export class HighlightDirective {
|
2015-11-19 19:59:22 -05:00
|
|
|
// #docregion ctor
|
2016-08-22 05:35:22 -04:00
|
|
|
constructor(private el: ElementRef, private renderer: Renderer) { }
|
2015-11-19 19:59:22 -05:00
|
|
|
// #enddocregion ctor
|
|
|
|
|
2016-06-12 18:41:33 -04:00
|
|
|
// #docregion mouse-methods, host
|
|
|
|
@HostListener('mouseenter') onMouseEnter() {
|
|
|
|
// #enddocregion host
|
|
|
|
this.highlight('yellow');
|
|
|
|
// #docregion host
|
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('mouseleave') onMouseLeave() {
|
|
|
|
// #enddocregion host
|
|
|
|
this.highlight(null);
|
|
|
|
// #docregion host
|
|
|
|
}
|
|
|
|
// #enddocregion host
|
2015-11-19 19:59:22 -05:00
|
|
|
|
2016-05-03 08:06:32 -04:00
|
|
|
private highlight(color: string) {
|
2016-08-22 05:35:22 -04:00
|
|
|
this.renderer.setElementStyle(this.el.nativeElement, 'backgroundColor', color);
|
2015-11-19 19:59:22 -05:00
|
|
|
}
|
|
|
|
// #enddocregion mouse-methods
|
|
|
|
|
|
|
|
}
|
2016-05-03 08:06:32 -04:00
|
|
|
// #enddocregion
|