2015-11-19 19:59:22 -05:00
|
|
|
// #docregion
|
2015-12-10 23:27:41 -05:00
|
|
|
import {Directive, ElementRef, Renderer, 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
|
|
|
|
})
|
|
|
|
|
|
|
|
export class Highlight {
|
|
|
|
// #docregion ctor
|
|
|
|
constructor(private el: ElementRef, private renderer: Renderer) {
|
|
|
|
}
|
|
|
|
// #enddocregion ctor
|
|
|
|
|
|
|
|
// #docregion mouse-methods
|
|
|
|
onMouseEnter() { this._highlight("yellow"); }
|
|
|
|
onMouseLeave() { this._highlight(null); }
|
|
|
|
|
|
|
|
private _highlight(color: string) {
|
2015-12-10 23:27:41 -05:00
|
|
|
this.renderer.setElementStyle(this.el, 'backgroundColor', color);
|
2015-11-19 19:59:22 -05:00
|
|
|
}
|
|
|
|
// #enddocregion mouse-methods
|
|
|
|
|
|
|
|
}
|
|
|
|
// #enddocregion
|