The Angular Style Guide says of Import line spacing:
- Consider leaving one empty line between third party imports and application imports.
- Consider listing import lines alphabetized by the module.
- Consider listing destructured imported symbols alphabetically.
- Why? The empty line separates your stuff from their stuff.
- Why? Alphabetizing makes it easier to read and locate symbols.
Looking at many Angular projects including Angular itself the convention is to import Angular (@angular
) modules first, then third-party modules (e.g. AngularFire2) and then our own modules (Services, Components, etc.) e.g. ./some-service.ts
.
Again it looks like it is the convention to import Services, then Models and then Components.
But what about Interfaces and Pipes, etc.? And what is the convention for importing 'nameless' or wildcard modules, e.g. the Firebase SDK or RxJs operators?
For example:
Example Service that Imports an RxJs Operator
import { Injectable } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import {
AngularFireDatabase,
FirebaseListObservable
} from 'angularfire2/database';
import * as firebase from 'firebase/app';
import 'rxjs/add/operator/take';
...
Or
import { Injectable } from '@angular/core';
import {
AngularFireDatabase,
FirebaseListObservable
} from 'angularfire2/database';
import * as firebase from 'firebase/app';
import { Observable } from 'rxjs/Observable';
import { AuthService } from './auth.service';
// `GridMetadata` is an Interface
import { GridMetadata } from './grid-metadata';
...