Last active
January 2, 2018 06:03
-
-
Save salmanx/39d67a0f6abbc18dadcb8546c823046c to your computer and use it in GitHub Desktop.
simple angular directive for dropdown menu in navbar
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, HostBinding, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[rbDropdown]' | |
}) | |
export class DropdownDirective { | |
private isOpen = false; | |
@HostBinding('class.open') get opened(){ | |
return this.isOpen; | |
} | |
@HostListener('click') open(){ | |
this.isOpen = true; | |
} | |
@HostListener('mouseleave') close(){ | |
this.isOpen = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment