Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended location for Domain Model classes

I am learning Angular 2 and I am using angular-cli to generate components and services. I am using the directory structure proposed by angular-cli (see screenshot below). I need to add some domain model object (e.g. User, Profile, etc.), but I don't know where to put them.

What is the recommended location for those objects in the directory structure?

Project structure

like image 737
Martin Avatar asked Jan 05 '23 23:01

Martin


2 Answers

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';
like image 104
Brocco Avatar answered Jan 15 '23 02:01

Brocco


If the domain model classes are used by all the components, it can be put in a model.ts file within shared folder.

like image 43
Jigar Avatar answered Jan 15 '23 02:01

Jigar