I recently developed a hamburger menu with a toggle function to display subcategories. Everything was working smoothly until I applied a filter. Once I search for a category using the filter, the toggle function stops working.
Here is a snippet of my HTML code:
<ul class="nav navbar-nav">
<div id="menuToggle" class="sidenav">
<ul id="menu">
<li>
<input class="form-control" type="search" [(ngModel)]="txtToSearch" placeholder="Search"/>
</li>
<li *ngFor="let category of (componentContents.dashboardMenu | dashboardFilter : txtToSearch); let i = index" >
<p class="toggleMenu" (click)="toggleMenu(i,componentContents.dashboardMenu)">{{category.category}}
</p>
<div *ngIf="category.show">
<ul id="{{(category.category).split(' ').join('-')}}" *ngIf="category.subCategory.length > 0">
<li *ngFor="let subCat of category.subCategory">
<a routerLink={{subCat.router}} routerLinkActive="active">
<span class="glyphicon glyphicon-bell" ></span>{{subCat.subcategory}} </a></li>
</ul>
</div>
<hr />
</li>
</ul>
In my component.ts file, this is the code I am using for the toggle function:
toggleMenu(index, catArry) {
if (catArry[this.prevClicked] && this.prevClicked !== index) {
catArry[this.prevClicked].show = false;
}
catArry[index].show = !catArry[index].show;
this.prevClicked = index;
}