【问题标题】:what is the best folder structure for parent and child components in angularAngular中父子组件的最佳文件夹结构是什么
【发布时间】:2020-04-12 16:51:29
【问题描述】:

上图是父子组件的实现结构。 我对角度基本文件夹结构有一个想法,但我需要一些小的说明。下面我提到了我目前创建的结构

app
├── features
│   └── feature 1
│        ├── parent A
│        │     └── parentA.component.ts 
│        │
│        ├── parent B
│        │     └── parentB.component.ts
│        │
│        ├── shared
│        │     └── models(models that are using inside the Feature 1)
│        └── core
│              └── service Q
│
├── shared
│    ├── components
│    │     └── header
|    └── models(models that are use inside every feature)
└── core
     └── service R

我的问题是:


  1. 在哪里创建子组件?
  2. 我也在功能内部使用共享文件夹和核心文件夹,对吗?

【问题讨论】:

  • “我也在 features 中使用 shared 和 core 文件夹”,将组件放在 shared 中的真正原因是在任何你想要的地方使用它们,所以这样做是可以的。

标签: angular module model parent-child directory-structure


【解决方案1】:

Answer 1. 您可以在父 A 文件夹下创建子组件,并应为父 A 文件夹添加路由模块。 答案 2. 是的,如果您的共享和核心模块的使用仅限于功能模块,那么您绝对可以按照当前流程进行。

应用程序 ├── 特色 │ └── 特色一 │ ├── 父母A │ │ └── 孩子Aa │ │ └── childAa.component.ts │ │ └── 儿童抗体 │ │ └── childAb.component.ts │ │ └── 父A-routing-module.ts │ │ │ ├── 父母B │ │ └── parentB.component.ts │ │ │ ├── 共享 │ │ └── 模型(Feature 1中使用的模型) │ └── 核心 │ └── 服务Q │ ├── 共享 │ ├── 组件 │ │ └── 标头 | └── 模型(每个特征中使用的模型) └── 核心 └── 服务R

【讨论】:

  • “child X”对父母双方都很常见,“child Z”也是“child Y”的孩子。我上传了一张实施结构的图片。请参考它,让我知道您对此有什么想法。
  • 在这种情况下,您应该在功能 1 本身中创建子 X 组件,并为两个父组件使用 feature1-routing。
猜你喜欢
  • 1970-01-01
  • 2017-04-06
  • 2018-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-26
  • 2016-09-29
  • 2012-12-15
相关资源
最近更新 更多