AngularJS - Handle repeated fragments like Header and Footer

前端 未结 1 366
长情又很酷
长情又很酷 2020-12-09 23:33

I have been trying to implement the header / footer in an Angular JS App. I was thinking of adding these as ng-include in the main index.html. However this would have worked

1条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 23:59

    Use a controller in the header/footer, as ivarni suggested. An example from an (experimental) app of my own:

    In the index.html, the header will display a dynamically generated menu, login/logout etc:

    
    

    The NavbarCtrl builds the appropriate scope for the app/main/navbar.html template. The template would be as follows (taking into account your needs - and irrelevant details removed):

    
    

    So the entire markup is hidden depending on the showHeader scope variable. It creates the menu dynamically (menuEntries). And depending on userData.loggedIn, the appropriate Login/Logout message.

    0 讨论(0)
提交回复
热议问题