Hide and Show angular 4 component depending on route

后端 未结 5 1736
渐次进展
渐次进展 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:08

    The accepted answer didn't work, because i think the variable will be assigned only once, then when we navigate, that variable will not be updated (component already initialized).

    here's how I did it.. We inject the router in the component we want to hide :

    constructor(private _router: Router){}
    

    then in our template :

    ... your component html ...

提交回复
热议问题