【问题标题】:ngIf with routingngIf 带路由
【发布时间】:2019-05-22 20:13:50
【问题描述】:

我需要帮助弄清楚如何使用 Angular 7 做到这一点:

IF route = page, THEN SHOW item1 OR item2; else SHOW item0

这是一个视觉效果:

/anyRoute, show item0

/route01, show item1

/route02, show item2

我对这一切还很陌生,我似乎对如何去做感到困惑。

提前致谢。

【问题讨论】:

    标签: angular7 show-hide


    【解决方案1】:

    在你的组件中

    import { Routes, Router } from 'node_modules/@angular/router';
    
    export class YourComponent implements OnInit{
         constructor(public router: Router ) {
        }
    }
    

    在 HTML 中:

    <ng-container *ngIf="router.url.includes('route01')">
        <p>Item0</p>
    </ng-container>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-07
      • 1970-01-01
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多