2015-11-19 19:59:22 -05:00
|
|
|
// #docregion
|
2016-01-26 16:42:17 -05:00
|
|
|
import {Directive, ElementRef, Input} from 'angular2/core';
|
2015-11-19 19:59:22 -05:00
|
|
|
|
|
|
|
@Directive({
|
2015-12-10 23:27:41 -05:00
|
|
|
selector: '[myHighlight]',
|
2015-11-19 19:59:22 -05:00
|
|
|
// #docregion host
|
|
|
|
host: {
|
|
|
|
'(mouseenter)': 'onMouseEnter()',
|
|
|
|
'(mouseleave)': 'onMouseLeave()'
|
|
|
|
}
|
|
|
|
// #enddocregion host
|
|
|
|
})
|
|
|
|
|
2015-12-16 22:38:07 -05:00
|
|
|
export class HighlightDirective {
|
2015-11-19 19:59:22 -05:00
|
|
|
// #docregion ctor
|
2016-01-26 16:42:17 -05:00
|
|
|
constructor(private el: ElementRef) { }
|
2015-11-19 19:59:22 -05:00
|
|
|
// #enddocregion ctor
|
|
|
|
|
|
|
|
// #docregion mouse-methods
|
|
|
|
onMouseEnter() { this._highlight("yellow"); }
|
|
|
|
onMouseLeave() { this._highlight(null); }
|
|
|
|
|
|
|
|
private _highlight(color: string) {
|
2016-01-26 16:42:17 -05:00
|
|
|
this.el.nativeElement.style.backgroundColor = color;
|
2015-11-19 19:59:22 -05:00
|
|
|
}
|
|
|
|
// #enddocregion mouse-methods
|
|
|
|
|
|
|
|
}
|
|
|
|
// #enddocregion
|