4

我正在学习 Angular 2,我正在使用 angular-cli 生成组件和服务。我正在使用 angular-cli 提出的目录结构(见下面的截图)。我需要添加一些域模型对象(例如用户、配置文件等),但我不知道将它们放在哪里。

这些对象在目录结构中的推荐位置是什么?

项目结构

4

2 回答 2

8

You will want to have your app-wide models stored at the root level (default: src/app) except that those values should be in the shared directory (src/app/shared).

If you generate those models with the CLI (from the project root directory) you will run:

ng generate class shared/profile model

which will yield:

src/app/shared/profile.model.ts
src/app/shared/profile.model.spec.ts

and also add a reference to the profile exports to the index.ts within the shared directory, so you can reference them (from the root component)

import { Profile } from './shared';
于 2016-06-01T18:57:46.330 回答
1

如果所有组件都使用域模型类,则可以将其放在共享文件夹中的 model.ts 文件中。

于 2016-06-01T04:24:09.287 回答