【问题标题】:Angular - Add a sidebar to a dashboard parent moduleAngular - 向仪表板父模块添加侧边栏
【发布时间】:2018-08-31 21:28:37
【问题描述】:

我构建了一个仪表板父模块,其中包含 2 个子模块:usersModule 和 statsModule

我想在父模块中显示一个侧边栏以跨子模块导航,但我想避免在每个模块中调用侧边栏。最好的方法是什么?

这是我目前得到的结果

# dashboardModule
    statsModule
        containers
        components
    usersModule
        containers
        components
    sharedModule
        services
        guards
        pipes
// other stuff
# homeModule
# eventsModule

谢谢

【问题讨论】:

    标签: angular architecture structure nav dashboard


    【解决方案1】:

    为此,我个人在我的 Angular2 项目中使用了 Material2 sidenav,效果很好。

    https://material.angular.io/components/sidenav/overview

    ** 猜我应该扩展** 我将它用作父组件中的“包装器”div,从该包装器中调用我的所有子组件。

    所以在我的例子中,我有一个“sidenav”组件,它是我的父组件,所有其他子组件都在该视图中被调用/渲染。

    代码示例

    <mat-sidenav-container>
      <mat-sidenav>
      </mat-sidenav>
      <Component-selector></Component-selector>
      //or you can place your router outlet here if your using a router
      <router-outlet></router-outlet>
    </mat-sidenav-container>
    

    这是我如何构建项目的图片。

    【讨论】:

    • 嗯,谢谢,但它都是关于架构的,我想知道如何构建我的模块以在所有子模块中显示这个导航栏
    • 你有github链接吗?因为我不明白如何将模块放入组件中
    • 查看修改后的代码示例。好吧,我将我所有的 Angular 2 项目都称为一个组件……这可能是我使用错误术语的误解。请参阅上面的代码示例,希望能进一步说明我是如何做到这一点的。
    • 这是一个链接,其中包含有关模块的更多信息以及将路由器与它们一起使用也可能有所帮助。 malcoded.com/posts/angular-fundamentals-modules
    • 我的结构看起来像这样 github.com/UltimateAngular/angular-pro-app-seed/tree/… 所以我不能在这里添加共享导航栏?
    猜你喜欢
    • 2016-08-08
    • 2020-09-12
    • 2015-09-24
    • 1970-01-01
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-12
    相关资源
    最近更新 更多