Get Instance of Sidenav


Topic: Get Instance of Sidenav

MIGU pro premium asked 2 weeks ago

How do get the instance of the sidenav from the html document?

I want to hide the sidenav with the hide() method in my ts file.

I tried in .ts: var element = document.getElementsByClassName("sidenav"); var sidenavInstance = mdb.Sidenav.GetInstance(element); sidenavInstance.hide();

HTML: <mdb-side-nav #sidenav class="side-nav" [fixed]="false">

Does not work in Angular...

FYI: Cannot upload Screenshots and Support page is extrem slow???!


Arkadiusz Idzikowski staff answered 2 weeks ago

This syntax is only valid in MDB5 (vanilla js) version. In Angular you need to use ViewChild decorator to get access to the component instance. For example:

import { SidenavComponent } from 'ng-uikit-pro-standard'

@ViewChild('sidenav') sidenav: SidenavComponent;

Then use hide method inside your method or ngAfterViewInit hook:

ngAfterViewInit(): void {
  this.sidenav.hide();
}

MIGU pro premium commented 2 weeks ago

Thank you for your fast answer. I will try it out.

Greets Michael


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Pro
  • Premium support: Yes
  • Technology: Angular
  • MDB Version: 10.1.1
  • Device: T560
  • Browser: Microsoft Edge
  • OS: Windows 10 Pro
  • Provided sample code: No
  • Provided link: No