2

我正在研究 Angular 的风格指南,在开发一个简单的应用程序时遇到了一些疑问!该应用程序是控制用户的证券交易所股票。所以需要:

  • 用于验证用户身份的模块(登录、注册和重置密码)
  • 一个模块,其中一个组件显示所有用户的股票,另一个组件用于添加新股票
  • 用于编辑用户个人资料的模块

身份验证模块将具有与应用程序的其余部分不同的布局(身份验证将只有一个集中式表单,而应用程序的其余部分将有一个导航栏作为菜单)。

问题 1:我将在 Auth 模块中创建一个名为 Layout 的组件,并将其仅用于身份验证视图;我在哪里创建布局组件或模块(我不知道是哪一个)以与应用程序的其余部分一起使用?我应该创建一个核心模块并在这个模块内创建一个布局模块吗?我应该创建一个核心模块和一个布局模块(核心之外)吗?

问题 2:我应该在哪里创建用于身份验证的防护?此守卫将用于股票和配置文件模块,以避免未登录的用户

问题 3:您将如何构建这个关于文件夹和文件的简单项目?

4

1 回答 1

2

Currently, I'm using this article to organize my Angular folder structure. Basically, we have three main folders - core, shared, views.

  • core: it has the CoreModule which provides all app common services. It's imported only once in AppModule. In this folder, I have services and guards subfolders because they are injectables (question 2 answer). guards I don't provide at CoreModule, I provide them at routing modules, i.e AppRoutingModule.
  • shared: it has the SharedModule which declare and exports all app common components, pipes, enums, classes and directives (all classes expect services and guards). SharedModule is imported by views module.
  • views: it gets all views modules (generally lazy-load modules).

The structure is (question 3 answer):

/app
|---/core
|   |---/guards
|   |---/services
|   |---core.module.ts
|
|---/shared
|   |---/components
|   |---/directives
|   ...
|   |---shared.module.ts
|
|---/views
|   |---/view-X
|       |---/components
|       |---/directives
|       |---view-X.component.html
|       |---view-X.component.css
|       |---view-X.component.spec.ts
|       |---view-X.component.ts
|       |---view-X.module.ts
|       |---view-X-routing.module.ts

In your case, could have three views folders/modules: authenticate, user-stock and user-edit. Each one will have the structure similar to the view-X folder example (question 1 answer).

于 2018-02-15T04:49:18.577 回答