How to *ngIf on router link?

后端 未结 3 1270
小鲜肉
小鲜肉 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:36

    I'm using the other approach.

    template:

    .ts file:

    import { Component, OnInit } from '@angular/core';
    import { Router } from '@angular/router';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.less']
    })
    
    export class AppComponent implements OnInit {
    
      constructor(private router: Router) {}
    
      ngOnInit() {}
    
      isHomeRoute() {
        return this.router.url === '/';
      }
    }
    

提交回复
热议问题