Coding

Clases (Style 03-01)

  • Use upper camel case when naming classes.

export class ExceptionService{
    constructor () { }
}

Constants (Style 03-02)

  • Declare variables with const if their values should not change during the application lifetime.

  • Consider spelling const variables in lower camel case.

  • tolerate existing const variables that are spelled in UPPER_SNAKE_CASE. Because some third party modules use it.

export const mockHeroes = ['Sam', 'Jill']; // Prefer
export const heroesURL = 'api/heroes'; // Prefer
export const VILLAINS_URL  = 'api/villains'; // Tolerate

Interfaces (Style 03-03)

  • Name an interface using upper camel case.

  • Naming an interface without an I prefix.

  • Consider using a class instead of an interface. Read about it.

import { Hero } from './hero.model';

@Injectable()
export class HeroCollectorService {
  hero: Hero;

  constructor() { }
}

Properties and Methods (Style 03-04)

  • Use lower camel case to name properties and methods.

  • Do not use prefixing private properties and methods with an underscore.

export class ToastService {
  message: string;
  private toastCount: number;

  hide() {
    this.toastCount--;
    this.log();
  }

  private log() {
    console.log(this.message);
  }
}

Import line spacing(Style 03-06)

  • Leave one empty line between third party imports and applications imports.

  • List the import lines alphabetized by the module.

  • List destructed imported symbols alphabetically.

import { Injectable } from '@angular/core';
import { Http }       from '@angular/http';

import { Hero } from './hero.model';
import { ExceptionService, SpinnerService, ToastService } from '../../core';