Topic: Subscribing to sidenav overlay click

itay pro asked 6 years ago


How can I Subscribe to sidenav overlay click, for being notified that the sidebar is closing on mobile devices ?

itay pro answered 6 years ago


After adding DI for (private renderer: Renderer2, public element: ElementRef) it works
Thanks

Damian Gemza staff answered 6 years ago


So please check this code, maybe this will fit your needs:
ngOnInit() {

this.renderer.listen(this.el.nativeElement.querySelector('#sidenav-overlay'), 'click', () => {

console.log('Overlay clicked');

});

}
Best Regards, Damian

itay pro answered 6 years ago


How can window:resize help if the window size doesn't change ?

Damian Gemza staff answered 6 years ago


Dear mdb2, There's no possibility to subscribe to sidenav overlay click to check when the sidebar is closing. But you can achieve similar behavior with HostListener with window:resize event. Please check my below code:
@ViewChild(SidenavComponent) sidenav: SidenavComponent;

@HostListener('window:resize') onresize() {

console.log(this.sidenav.shown);

}
Maybe it will fit your needs. We'll think in the future to add such behavior. Best Regards, Damian

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 6.2.2
  • Device: NA
  • Browser: NA
  • OS: NA
  • Provided sample code: No
  • Provided link: No