-
-
Save ackuser/615c17a29e5b645a77ec7297f6677d2e to your computer and use it in GitHub Desktop.
Angular 2 hover class directive
This file contains hidden or 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, Input, HostListener, Renderer, ElementRef } from '@angular/core'; | |
| @Directive({ selector: '[hoverClass]' }) | |
| export class HoverClassDirective { | |
| @Input() | |
| hoverClass: string; | |
| constructor( | |
| public elementRef: ElementRef, | |
| private renderer: Renderer | |
| ) { } | |
| @HostListener('mouseover') mouseover() { | |
| this.renderer.setElementClass(this.elementRef.nativeElement, this.hoverClass, true); | |
| } | |
| @HostListener('mouseout') mouseout() { | |
| this.renderer.setElementClass(this.elementRef.nativeElement, this.hoverClass, false); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment