Angular 2 Style Guide Angular 2 Style Guide

Angular 2 Style Guide Join the chat at https://gitter.im/mgechev/angular2-style-guide

The purpose of the following style guide is to present a set of best practices and style guidelines for the development of Angular 2 applications. If you are looking for an opinionated style guide for syntax, conventions, and structuring Angular 2 applications, then you can step in!

Disclaimer: This document is an alpha version which means that some of the guidelines will change and new ones will be added.

You are welcome to join the discussion of the best practices here.

The guidelines described below are based on:

  1. Angular 2 source code.
  2. Suggestions by Miško Hevery from his technical review of "Switching to Angular 2".
  3. My own development experience working in a team on large-scale Angular 2 application.
  4. John Papa's AngularJS 1.x style guide, for being consistent with the directory structure and testing across the different major versions of the framework.

Table of Contents

  1. Directory Structure
  2. Directives and Components
  3. Services and Dependency Injection
  4. Pipes
  5. Routing
  6. Forms
  7. Reusable libraries
  8. Testing
  9. Change Detection
  10. TypeScript specific practices
  11. ES2015 and ES2016 specific practices
  12. ES5 specific practices
  13. Tooling
  14. License

Directory Structure

Directives and Components

Services and Dependency Injection

Pipes

Routing

Forms

Reusable libraries

Waiting for announcement of official module format by angular-cli.

Table of Contents

Testing

Change detection

TypeScript specific practices

TypeScript code style

class MyClass {
  private myPrivateString:string = 'foobar';
  public myPublicString:string = 'foobar, but public';

  //exception: property field
  private _answerToEverything:number = 42;

  public get answerToEverything():number {
    return this._answerToEverything;
  }

  public set answerToEverything(value:number) {
    this._answerToEverything = value;
  }
}

TypeScript dependency injection

TSLint

ES2015 and ES2016 specific practices

ES5 specific practices

JSHint

JSCS

Tooling

License

MIT