Get Instance of Sidenav


Topic: Get Instance of Sidenav

MIGU pro premium asked 4 years 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 4 years 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 4 years ago

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

Greets Michael


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
  • User: Pro
  • Premium support: Yes
  • Technology: MDB Angular
  • MDB Version: 10.1.1
  • Device: T560
  • Browser: Microsoft Edge
  • OS: Windows 10 Pro
  • Provided sample code: No
  • Provided link: No