import { NgModule, Optional, SkipSelf } from '@angular/core'; import { CommonModule } from '@angular/common'; import { ContactService } from './contact.service'; @NgModule({ declarations: [], imports: [ CommonModule ] }) export class ContactModule { constructor( @Optional() @SkipSelf() parentModule: ContactModule ) { if (parentModule) { throw new Error('ContactModule is already loaded. Import it in the AppModule only'); } } static forRoot() { return { ngModule: ContactModule, providers: [ ContactService ] } } }