angular - *ngIf 用于所有子路由
问题描述
我想弄清楚如何为所有子路由显示带有 *ngIf 的容器。
像:
<div *ngIf="router.url === /page/**"></div>
因此,当我在“页面”以及“页面”的所有子页面时,都会显示此容器。
谢谢你的帮助
解决方案
public currentLink: string;
constructor(private router: Router){
this.currentLink = this.router.url;
}
if(this.currentLink.startsWith('/page/')) this.flag = true;
else this.flag = false;
<div *ngIf="flag"></div>
> you can get the URL using observable also
推荐阅读
- node.js - npm 错误!asyncWrite 不是函数
- c# - 如何使用自动生成的 AssemblyInfo 应用程序集:ThemeInfo 属性?
- react-native - onEndReached 在任何 ScrollView React 本机中都无法正常工作
- android - 跟踪写入 adb 文件的事件数
- c# - 聚合根可以引用另一个根吗?
- html - 引导程序 3 到引导程序 4
- google-chrome - 如何让 Chrome 的自动完成下拉菜单仅在我开始输入后出现(而不是在最初的鼠标点击时)?
- android - RemoteViews setImageViewBitmap()不起作用
- dialogflow-es - 如何在 Dialogflow 数字字符串实体中支持“双”和“三”?
- azure-webjobs - 将 Azure 主题消息接收到 Web 作业中?