How to *ngIf on router link?

后端 未结 3 1274
小鲜肉
小鲜肉 2021-02-01 16:01

I need to show some content on certain page, in other pages it shouldn\'t be visible. How do I achieve it ? it doesn\'t work

*ngIf=\"[routerLink]=\"[\'/home\']\"<

3条回答
  •  长发绾君心
    2021-02-01 16:41

    You can inject Router from '@angular/router' and get the current route you're on.

    For example:

    // mycomponent.component.ts
    class MyComponent {
        constructor(public router: Router) {
    
        }
    }
    
    // mycomponent.component.html
    

提交回复
热议问题