src/app/layouts/main-layout/dropdown.directive.ts
selector | [sidebarDropdown] |
Properties |
|
Methods |
HostBindings |
HostListeners |
class.open |
class.open:
|
click |
Arguments : '$event.target.className'
|
click(srcClass: )
|
close |
close()
|
Returns :
void
|
Private isOpen |
isOpen:
|
Default value : false
|
Private targetClassName |
targetClassName:
|
Default value : "nav-link nav-dropdown-toggle"
|
import {Directive, HostBinding, HostListener} from "@angular/core";
@Directive({
selector: '[sidebarDropdown]',
exportAs: 'sidebarDropdown'
})
export class DropdownDirective {
private targetClassName = "nav-link nav-dropdown-toggle";
private isOpen = false;
@HostBinding('class.open') get opened() {
return this.isOpen;
}
@HostListener('click', ['$event.target.className']) open(srcClass) {
if (srcClass === this.targetClassName) {
this.isOpen = !this.isOpen;
}
}
close() {
this.isOpen = false;
}
}