Skip to main content
<FrontBackGeek/>
angular-icon

How to organize your angular application using modules

FrontBackGeek 3 years ago

Angular Basics

  • Its a javascirpt framework
  • Its different from angular js
  • Used to build powerful frontend applications.
  • Its used for rapid application development and code generation.

Some of important features of angular applications are :

  1. Components
  2. Services
  3. Routing
  4. Lazy Loading
  5. Testing
  6. Data binding
  7. HTTP Module
  8. Form Module (Template Driven and Reactive Form)
  9. Pipes
  10. Directives
  11. Observables

 Ways to organize code :

To organize angular code we should use lazy loading, to get this we should create modules according to the features of application and we should create all sub components inside the module folder.

Benefits of feature module is it allows lazy loading so it load module when it require not on the time of app module load.

Single Responsibility Principle (SRP) :

  • RULE OF ONE
  • Define one component or service per file.
  • Define small functions to reuse code.
  • Use consistent names for all symbols.
  • Use dashes to separate words in the descriptive names.
  • Use consistent names for all assets named after what they represent.
  • Use consistent names for all services named after their features.

LIFT Principle :

  • Locate code fast
  •  Identify
  • Flat (Easy file structure)
  • Try to Dry

Convention based approach :

  •  Structure our components in folders
  • All services in service folder

 Feature based approach :

  •  Each module has its own component, service and pipe files.
  • All files inside the feature folder.

 Some Useful ng Commands :

Component : ng generate component component_name

Service : ng generate service service_name

Pipe : ng generate pipe pipe_name

Directive : ng generate directive directive_name

Module : ng generate module module_name –route module_name –module app

Library ; ng generate library ng-shared (This will create the same folder like src folder)

© FrontBackGeek.com 2021 All Rights Reserved. DMCA.com Protection Status