Hide and Show angular 4 component depending on route

后端 未结 5 1745
渐次进展
渐次进展 2021-02-01 19:03

Hi there Im not sure if this is possible... basically I want to be able to show a component but only if the route matches and hide a component if the route matches Ive tried thi

5条回答
  •  长情又很酷
    2021-02-01 19:25

    check the router.url in the template:

    
     //component I want hidden unless url /home
    
    
    

    in app.component.ts inject the router.

    export class AppComponent {
      title = 'app';
      router: string;
    
      constructor(private _router: Router){
    
              this.router = _router.url; 
        }
    }
    

提交回复
热议问题