Giter Club home page Giter Club logo

angular-best-practices's Introduction

angular best practices

How to run

  1. npm install -g @angular/cli
  2. npm start

Angular Best practices recommendations

  1. Use angular-cli.

  2. Prefer LIFT approach:

    • Locate code quickly;
    • Identify code in glance;
    • Flatten folder structure;
    • Try do not DRY.
  3. 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)
  4. One item per file (use multiply component for on big component)

  5. File naming (use *.component, *.service, *.model)

  6. Make file names and class names consistence

Code Style

  1. Single Responsibility
  2. Use small functions
  3. Prefer Immutable state
  4. Prefixing component selectors
  5. Using separate CSS and template files
  6. Decorating input and output properties
  7. Delegating complex logic to services
  8. Component member sequence
  9. Implementing lifecycle hook interfaces
  10. When to create components

Angular performance

  1. Ahead-of-time compilation (Compile before deploy) when use angular-cli npm run build -- --prod

  2. Lazy Loading declare in route loadChildren command

  3. 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';

  4. Use pure pipes

  5. Use trackBy to re-render only items what was changed

  6. Don't Lazy-Load the Default Route

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.