Project Structure
The project is broken down into three main file categories (examples provided below each category):
Component
Service
Model
At a high level, the libraries file structure will be set up with these three main file categories in mind. There will be a folder for each category where all files of that type will live.
The services and models folders will largely be flat file structures underneath. However, if you include tests with a service or model then they need to be grouped together in a subfolder with the corresponding service or model.
The nature of Angular 2's components require that several files be grouped together under a subfolder.
In order to facilitate easier importing of components, services and models in other parts of the library (the main app module, for example), each category folder will contain anindex.tsfile. This file will simply_import_the entire contents of the folder it lives in and then_export_them as a group for easier consumption later on. Examples:
a services folder
it's corresponding
index.ts
file
how the
index.ts
file is used later to simplify importing
The Angular team has provided a set of command line tools calledangular-clito, among other things, help you generate new components, services and models in a way that follows the standards outlined above. In order to maintain a strict and consistent style of organization throughout the project, you _must _use this tool to generate your new files. Provided are examples of how to generate each of these file types and the result of each command.
Component
Service
Model
One final thing to keep in mind is that, although this tool is an excellent resource for helping to follow best practices and consistent organizational style, it does not handle one key detail when creating newcomponents. To avoid naming collisions between your components and third-party components you may include in the project, we will be prefixing our component selectors withcf(Cedrus Fusion). If you run the above commands for generating a component and open the.component.ts_file that is generated, you will see that the component selector isapp-my-new-component. You need to change_app_to_cf. This will result in the proper selector format for the librarycf-my-new-component.
Last updated