【发布时间】:2017-03-30 19:40:59
【问题描述】:
在我的应用程序中,我必须实现隐藏和显示侧边菜单。默认情况下,页面菜单在单击切换菜单时打开,我必须隐藏侧面菜单。我该如何实现。
我拥有的是:
app.component.html, nav.component.html
<div class="menu-toggler sidebar-toggler">
<span></span>
</div>
<ul>
<li class="nav-item ">
<a class="nav-link nav-toggle">
<i class="icon-diamond"></i>
<span class="title">Name</span>
<span class="arrow"></span>
</a>
</li>
</ul>
我的服务.ts
export class GlobalService {
public collapse;
constructor() { }
setValue(val: boolean) {
this.collapse = val;
}
getValue() {
return this.collapse;
}
编辑
app.component.html
<div *ngIf="!toggle()"class="menu-toggler sidebar-toggler">
<span></span>
</div>
app.component.ts
import { GlobalService } from "path";
export class AppComponent {
toggle() {
this.globalService.setValue(false);
}
}
如何在单击菜单切换 (app.compnent.html) 时隐藏此列表(在 nav.html 中)?任何帮助都会非常显着。我是 Angular 新手。
【问题讨论】:
-
我按照你们的建议创建了一个全球服务。但是我对如何隐藏侧边栏感到困惑。这里包括我的全局服务和编辑的文件。
标签: javascript html css angular