2016-09-19 19:57:59 -07:00
|
|
|
// #docregion
|
2016-09-13 14:39:39 -07:00
|
|
|
import { Directive, ElementRef, Input, OnChanges, Renderer } from '@angular/core';
|
|
|
|
|
|
|
|
@Directive({ selector: '[highlight]' })
|
2016-09-19 19:57:59 -07:00
|
|
|
/** Set backgroundColor for the attached element to highlight color
|
|
|
|
* and set the element's customProperty to true */
|
2016-09-13 14:39:39 -07:00
|
|
|
export class HighlightDirective implements OnChanges {
|
|
|
|
|
2016-09-19 19:57:59 -07:00
|
|
|
defaultColor = 'rgb(211, 211, 211)'; // lightgray
|
2016-09-13 14:39:39 -07:00
|
|
|
|
|
|
|
@Input('highlight') bgColor: string;
|
|
|
|
|
|
|
|
constructor(private renderer: Renderer, private el: ElementRef) {
|
|
|
|
renderer.setElementProperty(el.nativeElement, 'customProperty', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnChanges() {
|
|
|
|
this.renderer.setElementStyle(
|
|
|
|
this.el.nativeElement, 'backgroundColor',
|
2016-09-19 19:57:59 -07:00
|
|
|
this.bgColor || this.defaultColor );
|
2016-09-13 14:39:39 -07:00
|
|
|
}
|
|
|
|
}
|