gpt4 book ai didi

Angular2 - 项目结构

转载 作者:太空狗 更新时间:2023-10-29 18:20:41 25 4
gpt4 key购买 nike

我将开始一个新的 Angular2 项目,我试图了解 Angular2 应用程序的最佳结构。让我将页面设置为 homeauto-galleriesnearest-galleriesbrandscarsselected-car。而导航顺序是

home -> auto-galleries -> nearest-galleries

home -> brands -> cars -> selected-car

为获得最佳方法,我应该为每个页面使用组件还是模块?如果模块是更好的方法,我应该使用分层模块还是都在根模块下的同一级别?

比如下面的结构有多好:

app
├--- app.module.ts
├--- app.component.ts
├--- home.html
├--- brands
| ├--- brands.module.ts
| ├--- brands.component.ts
| ├--- brands.html
| ├--- cars
| ├--- cars.module.ts
| ├--- cars.component.ts
| ├--- cars.html
| ├--- selected-car
| ├--- selected-car.module.ts
| ├--- selected-car.component.ts
| ├--- selected-car.html
|
├--- auto-galleries
├--- auto-galleries.module.ts
├--- auto-galleries.component.ts
├--- auto-galleries.html
├--- nearest-galleries
├--- nearest-galleries.module.ts
├--- nearest-galleries.component.ts
├--- nearest-galleries.html

或者这种结构更好:

app
├--- app.module.ts
├--- app.component.ts
├--- home.html
├--- brands
| ├--- brands.module.ts
| ├--- brands.component.ts
| ├--- brands.html
|
├--- cars
| ├--- cars.module.ts
| ├--- cars.component.ts
| ├--- cars.html
|
├--- selected-car
| ├--- selected-car.module.ts
| ├--- selected-car.component.ts
| ├--- selected-car.html
|
├--- auto-galleries
| ├--- auto-galleries.module.ts
| ├--- auto-galleries.component.ts
| ├--- auto-galleries.html
|
├--- nearest-galleries
├--- nearest-galleries.module.ts
├--- nearest-galleries.component.ts
├--- nearest-galleries.html

注意:这只是一个简单的例子,我的应用程序更适合模块化结构:)

最佳答案

Angular 文档在他们的 Style Guide 中对此有一些建议:

<project root>
src
app
core
core.module.ts
exception.service.ts|spec.ts
user-profile.service.ts|spec.ts
heroes
hero
hero.component.ts|html|css|spec.ts
hero-list
hero-list.component.ts|html|css|spec.ts
shared
hero-button.component.ts|html|css|spec.ts
hero.model.ts
hero.service.ts|spec.ts
heroes.component.ts|html|css|spec.ts
heroes.module.ts
heroes-routing.module.ts
shared
shared.module.ts
init-caps.pipe.ts|spec.ts
text-filter.component.ts|spec.ts
text-filter.service.ts|spec.ts
villains
villain
...
villain-list
...
shared
...
villains.component.ts|html|css|spec.ts
villains.module.ts
villains-routing.module.ts
app.component.ts|html|css|spec.ts
app.module.ts
app-routing.module.ts
main.ts
index.html
...
node_modules/...
...

+ Style-04-04 :

Do keep a flat folder structure as long as possible.

关于Angular2 - 项目结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41868474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com