如何在 *ngIf 中捕捉路线 [英] How to catch routes in *ngIf

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

问题描述

所以我想让我的 Header 上的锚元素在点击特定页面时消失.当该页面被点击时,如何在 *ngIf 中捕获 url.

我有一个标题,所有页面都将保持不变.当我被路由到/home 时,只需要隐藏一个锚元素.如何在 *ngIf 中捕获这个/home"?

*ngIf = "href='/home'" 不起作用.有其他选择吗?

解决方案

//mycomponent.component.ts类我的组件{构造函数(私有路由器:路由器){}}//mycomponent.component.html<div *ngIf="router.url === '/some/route'">

So I want to make an anchor element on my Header disappear when a specific page is hit. How can I catch the url in the *ngIf when that page is hit.

I have a header which will remain same for all pages. Just need to hide an anchor element when I am routed at /home. How to catch this "/home" in *ngIf?

*ngIf = "href='/home'" is not working. Any alternatives?

解决方案

//mycomponent.component.ts
class MyComponent {
    constructor(private router: Router){

    }
}

//mycomponent.component.html
    <div *ngIf="router.url === '/some/route'">

    </div>

这篇关于如何在 *ngIf 中捕捉路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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