2016-06-01 20 views
1

我正在學習Angular 2,我正在使用angular-cli來生成組件和服務。我正在使用angular-cli提供的目錄結構(請參見下面的截圖)。我需要添加一些域模型對象(例如用戶,配置文件等),但我不知道把它們放在哪裏。Domain Model類的推薦位置

這些對象在目錄結構中的推薦位置是什麼?

Project structure

回答

3

除了那些值應位於shared目錄(src/app/shared)之外,您將希望將您的應用程序範圍模型存儲在根級別(默認值:src/app)。

如果生成的CLI那些模型(從項目的根目錄),你會遇到:

ng generate class shared/profile model 

這將產生:

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

,並添加到profile出口參考到共享目錄下的index.ts,因此您可以引用它們(來自根組件)

import { Profile } from './shared'; 
0

如果域模型類由所有的組分使用時,它可以放在共享文件夾內的文件model.ts。