ngIf 带路由 [英] ngIf with routing

查看:24
本文介绍了ngIf 带路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need help figuring out how to do this with Angular 7:

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

这是一个视觉效果:

/anyRoute,显示 item0

/route01,显示 item1

/route02,显示 item2

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

I am fairly new to all this and I seem to get confused with how to go about it.

提前致谢.

推荐答案

在你的组件中

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>

这篇关于ngIf 带路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆