File

src/app/shared/_directives/menu-toggle.directive.ts

Metadata

Selector [appMenuToggle]

Index

Methods

Constructor

constructor(elementRef: ElementRef, renderer: Renderer2)
Parameters :
Name Type Optional
elementRef ElementRef No
renderer Renderer2 No

Methods

onMenuToggle
onMenuToggle()
Returns : void
import { Directive, ElementRef, Renderer2 } from '@angular/core';

@Directive({
  selector: '[appMenuToggle]',
})
export class MenuToggleDirective {
  constructor(private elementRef: ElementRef, private renderer: Renderer2) {
    this.renderer.listen(this.elementRef.nativeElement, 'click', () => {
      this.onMenuToggle();
    });
  }

  // Menu Trigger
  onMenuToggle(): void {
    const sidebar: HTMLElement = document.getElementById('sidebar');
    sidebar?.classList.toggle('active');
    const content: HTMLElement = document.getElementById('content');
    content?.classList.toggle('active');
    const sidebarCollapse: HTMLElement = document.getElementById('sidebarCollapse');
    sidebarCollapse?.classList.toggle('active');
  }
}

result-matching ""

    No results matching ""