當我點擊一位家長時,所有的父母都會呈現他們的孩子,並且與隱藏相似。我是角2的新手。請推薦。Angular hide show not working
所以我有以下組成部分
import { Component, Input } from '@angular/core';
@Component({
selector: 'sidebar-cmp',
templateUrl: 'sidebar.html',
styleUrls: [
'sidebar.scss'
]
})
export class SidebarComponent {
@Input() tenants = 0;
showMenu: string = '';
addExpandClass(element: any) {
if (element === this.showMenu) {
this.showMenu = '0';
} else {
this.showMenu = element;
}
}
}
相應的HTML
<nav class="sidebar">
<ul class="list-group" *ngFor="let tenant of tenants ;trackBy: trackId">
<div class="nested-menu">
<a class="list-group-item" (click)="addExpandClass('tenant.id')">
<span><i class="fa fa-th-list"></i> {{tenant.name}}</span>
</a>
<li class="nested" [ngClass]="{'expand' : showMenu === 'tenant.id' }">
<ul class="submenu">
<li>
<a href><span>Submenu</span></a>
</li>
<li>
<a href><span>Submenu</span></a>
</li>
</ul>
</li>
</div>
</ul>
</nav>
你的意思是這樣的[摺疊式菜單](http://bootsnipp.com/snippets/featured/accordion-menu) ? 一次只打開一個菜單的情況。 –