首页 > 解决方案 > *ngIf 用于所有子路由

问题描述

我想弄清楚如何为所有子路由显示带有 *ngIf 的容器。

像:

<div *ngIf="router.url === /page/**"></div>

因此,当我在“页面”以及“页面”的所有子页面时,都会显示此容器。

谢谢你的帮助

标签: angularangular-ui-routerangular-ng-if

解决方案


    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 

推荐阅读