Patrice Chalin e5b11d456c docs(guide/attribute-directives): follow-up to #1654 (#1765)
- Updated Dart code to match TS.
- Ran dartfmt.
- Enabled e2e tests; suites passed:
  - public/docs/_examples/attribute-directives/dart
  - public/docs/_examples/attribute-directives/ts
- Prose copyedits.
2016-06-28 13:15:51 -07:00

37 lines
801 B
TypeScript

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