Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Get Instance of Sidenav

MIGU premium asked 3 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 3 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 premium commented 3 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

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