Created
June 22, 2018 13:02
-
-
Save rayonhunte/ead055c662c705d8a7fd7d8d201a73e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, Renderer2, ElementRef, HostListener, HostBinding, Input } from '@angular/core'; | |
import { MockNgModuleResolver } from '@angular/compiler/testing'; | |
@Directive({ | |
selector: '[appBetterHighlight]' | |
}) | |
export class BetterHighlightDirective { | |
@Input() defaultColor = 'transparent'; | |
@Input() highlightColor = 'blue'; | |
@HostBinding('style.backgroundColor') background: string;; | |
constructor(private elRef: ElementRef, private renderer: Renderer2) { } | |
ngOnInit(): void { | |
this.background = this.defaultColor; | |
this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'blue'); | |
} | |
@HostListener('mouseenter') mouseover(eventData: Event) { | |
// removed for host binding example | |
// this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'pink'); | |
this.background = this.highlightColor; | |
} | |
@HostListener('mouseleave') mouseleave(eventData: Event) { | |
// this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'transparent'); | |
this.background = this.defaultColor; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment