【问题标题】:Angular 2 - app.component contents?Angular 2 - app.component 内容?
【发布时间】:2017-10-02 16:12:12
【问题描述】:

我想知道。您建议在 app.component 文件中包含什么?我对此的直接想法只是在其中包含导航栏和页脚之类的东西。因为这些是在整个应用程序中唯一不变的元素。这是正确的推理还是您会采取不同的做法?

【问题讨论】:

    标签: angular architecture


    【解决方案1】:

    当我使用 Angular 构建应用程序时,我通常只引用 app.component 中的布局组件。例如。 app.component.html:

    <app-layout class="wrapper"></app-layout>
    

    布局组件将包含页眉、页脚和路由器出口。比如:

    <!-- Top navbar-->
    <app-header></app-header>
    <!-- Page content-->
    <div class="content-wrapper">
        <router-outlet></router-outlet>
    </div>    
    <!-- Page footer-->
    <app-footer></app-footer>
    

    我个人喜欢这种方法,因为它分解了组件,使它们具有明确和明确的目的。

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2017-07-22
      • 2016-12-25
      • 1970-01-01
      • 2017-02-01
      • 2016-11-17
      • 2017-07-30
      • 2018-09-28
      • 1970-01-01
      相关资源
      最近更新 更多