angularangular2-routingangular2-template

How to catch routes in *ngIf


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?


Solution

  • mycomponent.component.ts

    import { Router } from '@angular/router'
    
    class MyComponent {
        constructor(public router: Router) { }
    }
    

    mycomponent.component.html

    <div *ngIf="router.url === '/some/route'">
        <!-- … -->
    </div>