angular 2 - how to hide nav bar in some components

后端 未结 9 710
半阙折子戏
半阙折子戏 2020-12-04 16:07

I am created nav bar separately in nav.component.html ,how to hide nav bar in some components like login.component.

nav.component.html

9条回答
  •  执笔经年
    2020-12-04 16:19

    Add *ngIf='!showNav' in template

    And in LoginComponent

    showNav = true;
    

    This will show nav rest of the all the pages , if you want to hide in any pages just put showNav = true; in that component.

    How it works :

    First for it will check for showNav variable but it will not be available , so it will return false for the other pages where we want to show menu , so need to declare that variable any other pages.

    In login page we set the value to true, so it will make it false and hide the nav.

提交回复
热议问题