├── src
│ ├── 应用程序
│ │ ├── 核心
│ │ │ ├──服务
│ │ │ ├── core.module.ts
│ │ ├── 共享
│ │ │ ├── 产品形态
│ │ │ │ ├──product-form.component.ts|html|css
│ │ │ │ ├── 产品表单.service.ts
│ │ │ │
我有 2 个模块 core 和 shared。我在 shared 模块中有 product-form 组件。而且 product-form 有 product-form.service。我使用该服务来格式化表单数据并将其再次返回到 product-form.component。该服务仅由 product-form.
使用,所以我需要知道,我可以将 product-form.service 放在 product-form 组件中,如上面的结构吗?或者我应该将它放在 core 模块服务文件夹中?
我是 Angular 的初学者。
谢谢你。
是的,可以。设计上很少有接触:
src
|-app
| |-core
| |-services
|-shared
| |-components
| | |-my-component
| | |-my-component.component.html
| | |-my-component.compoennt.ts
| | |-my-component.service.ts
但是如果你问我该怎么做,我将创建一个库并将我所有共享的服务和组件放在那里。在这种情况下,它们将在库中单独烘焙,主应用程序将仅调用所需的内容。
projects
|-my-library
| |-src
| | |-lib
| | |-components
| | | |-my-component.component.html
| | | |-my-component.component.ts
| | |-services
| | | |-my-component.service.ts
src
|-app
| |-core
| | |-services
| ...
如果您想了解有关库的更多信息:https://angular.io/guide/creating-libraries