html - How to hide my left nav menu only on certain pages
问题描述
I am working on a angular5/html 5 project. I have a side-nav-menu component that displays on all the pages of my app. The thing is that this side-nav-menu component is dynamic and automatically updates if any more pages are added in the app.
Now what i want to do is hide this menu only on certain pages. for example i want to remain visible on page 1-5, hidden on page 6-8 and again visible on 9 and 10. How should i do this?
This is my edited html code for side-nav-menu:
<aside>
<div class="sidebar">
<nav>
<div class="sidebar__wrap">
<ol class="left-nav">
</ol>
</div>
</nav>
</div>
</aside>
解决方案
请参阅如何获取当前路线
您可以从Router
sideNav 的父组件或 sideNav 本身和*ngIf
模板上的对象中读取路线:
constructor(router: Router) {
router.events.subscribe(event => {
if (router.url === 'SOMEROUTE') {
this.showSideNav = false;
}
}
}
然后设置*ngIf
在你身边的导航到showSideNav
。
推荐阅读
- postman - 将新的测试结果附加到现有的纽曼报告中
- angular - 重置日期选择器的问题 - Angular 2
- python - 在一个数据库命中评估整个 django 查询集
- javascript - 带有链接列表的响应式打字新闻自动收报机
- awk - 改变大宗和小宗案件
- php - 如何 JSON 编码多维数组?
- javascript - 如何通过按下按钮(chart.js)制作新图表?
- c# - 在 WCF 中使用 X509 证书签署 SOAP 正文和时间戳
- postgresql - 将 PostgreSQL 与 App Engine 标准结合使用
- php - 删除价格小数的最后一位。WordPress(PHP)