How to run
- npm install -g @angular/cli
- npm start
Angular Best practices recommendations
-
Use angular-cli.
-
Prefer LIFT approach:
- Locate code quickly;
- Identify code in glance;
- Flatten folder structure;
- Try do not DRY.
-
Folder structure (Group feature first then, component first):
- App Module (root of the application)
- Core Module (shared singelton services across multiply modules in app, angular create new service for each lazy loaded service, app level component for example navigation bar)
- Shared Module (shared components, directives and pipes for example load spinner)
- Feature Module (feature level components, directives, pipes, services)
-
One item per file (use multiply component for on big component)
-
File naming (use *.component, *.service, *.model)
-
Make file names and class names consistence
Code Style
- Single Responsibility
- Use small functions
- Prefer Immutable state
- Prefixing component selectors
- Using separate CSS and template files
- Decorating input and output properties
- Delegating complex logic to services
- Component member sequence
- Implementing lifecycle hook interfaces
- When to create components
Angular performance
-
Ahead-of-time compilation (Compile before deploy) when use angular-cli npm run build -- --prod
-
Lazy Loading declare in route loadChildren command
-
Size of the bundles
npm run build -- --prod --source-maps=true
then use the source map explorer
use explicit imports to avoid loading of full library
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map'; -
Use pure pipes
-
Use trackBy to re-render only items what was changed
-
Don't Lazy-Load the Default Route