Topic: Access sidenav from ts file

itkaufmann priority asked 2 years ago


Is it possible to access the sidenav from a ts file? In my case I would like to show or hide the sidenav in the ngOnInit function of the component where I use the sidenav.

Moreover, I would like to know if there is a possibility to set the initial expanded/collapsed state of the sidenav?


Arkadiusz Idzikowski staff answered 2 years ago


@itkaufmann In order to get access to the component methods you need to use the Angular template reference variable (for example #sidenav) in your HTML file and @ViewChild decorator in ts file. Here is an example:

<mdb-sidenav #sidenav="mdbSidenav">

@ViewChild('sidenav', { static: true }) sidenav: MdbSidenavComponent;

We will add this information to the API section in the component documentation.

As for the initial state settings, there is a [hidden] input by default set to true. However, we have received information about certain problems with this solution and are currently working on a fix.



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue

  • User: Priority
  • Premium support: Yes
  • Technology: MDB Angular
  • MDB Version: MDB5 1.3.0
  • Device: Any
  • Browser: Google Chrome Version 95.0.4638.
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No