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

46 lines
1.0 KiB
Dart

// #docplaster
// #docregion full
import 'package:angular2/core.dart';
@Directive(selector: '[myHighlight]')
// #docregion class
class HighlightDirective {
String _defaultColor = 'red';
final dynamic _el;
HighlightDirective(ElementRef elRef) : _el = elRef.nativeElement;
// #enddocregion class
// #docregion defaultColor
@Input()
set defaultColor(String colorName) {
_defaultColor = (colorName ?? _defaultColor);
}
// #enddocregion defaultColor
// #docregion class
// #docregion color
@Input('myHighlight')
String highlightColor;
// #enddocregion color
// #docregion mouse-enter
@HostListener('mouseenter')
void onMouseEnter() => _highlight(highlightColor ?? _defaultColor);
// #enddocregion mouse-enter
@HostListener('mouseleave')
void onMouseLeave() => _highlight();
void _highlight([String color]) {
if (_el != null) _el.style.backgroundColor = color;
}
}
// #enddocregion class
// #enddocregion full
/*
// #docregion highlight
@Input() String myHighlight;
// #enddocregion highlight
*/