| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | // #docplaster
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-04-27 11:28:22 -07:00
										 |  |  | import {Directive, ElementRef, Input} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-03-26 12:18:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Directive({ | 
					
						
							|  |  |  |   selector: '[myHighlight]', | 
					
						
							|  |  |  |   host: { | 
					
						
							|  |  |  |     '(mouseenter)': 'onMouseEnter()', | 
					
						
							|  |  |  |     '(mouseleave)': 'onMouseLeave()' | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class HighlightDirective { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @Input('myHighlight') highlightColor: string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private _el: HTMLElement; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   constructor(el: ElementRef) { | 
					
						
							|  |  |  |     this._el = el.nativeElement; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onMouseEnter() { this._highlight(this.highlightColor || 'cyan'); } | 
					
						
							|  |  |  |   onMouseLeave() { this._highlight(null); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private _highlight(color: string) { | 
					
						
							|  |  |  |     this._el.style.backgroundColor = color; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |