35 lines
770 B
TypeScript
Raw Normal View History

2016-06-13 00:41:33 +02:00
/* tslint:disable:no-unused-variable */
// #docregion
import { Directive, ElementRef, HostListener, Input } from '@angular/core';
@Directive({
2016-06-13 00:41:33 +02:00
selector: '[myHighlight]'
})
export class HighlightDirective {
// #docregion ctor
constructor(private el: ElementRef) { }
// #enddocregion ctor
2016-06-13 00:41:33 +02: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
private highlight(color: string) {
this.el.nativeElement.style.backgroundColor = 'yellow';
}
// #enddocregion mouse-methods
}
// #enddocregion