Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClarityNg: how to close sidenav on click button inside

I have a basic clarity angular template with search in sidenav. When I click find button in sidenav on mobile device, sidenav does not disappear. How I can close sidenav using angular?

like image 345
Sergey Slonimsky Avatar asked Dec 03 '25 23:12

Sergey Slonimsky


1 Answers

The most straightforward solution would be for you to get a reference to the NavLevelDirective instance for the sidenav with @ViewChild, and all its close() method.

For instance, add a reference variable in your template:

<nav #mySidenav class="sidenav" [clr-nav-level]="2">
    <app-sidebar></app-sidebar>
</nav>

Then access it in your app's component by using:

@ViewChild("mySidenav", {read: NavLevelDirective}) sidenav: NavLevelDirective;

and just call sidenav.close() when the user clicks the "find" button.

like image 83
Eudes Avatar answered Dec 05 '25 15:12

Eudes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!