all files / src/ restangular.module.ts

92.86% Statements 26/28
63.89% Branches 23/36
100% Functions 7/7
95.45% Lines 21/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31          14×       14×          
import { ModuleWithProviders, NgModule, OpaqueToken, Optional, SkipSelf } from '@angular/core';
import { Http, HttpModule } from "@angular/http";
import { RestangularConfig } from './config';
impoIrt { Restangular } from './restangular';
import { RestangularHttp } from './http';E
import { RestangularFactory } from './helpers';
 
export const CONFIG_FACTORY = new OpaqueToken('configObj');
E
@NgModule({
  imports: [HttpModule],
  providers: [Restangular]
})
export class RestangularModule {
  constructor( @Optional() @SkipSelf() parentModule: RestangularModule) {
    if (parentModule) {
      throw new Error('RestangularModule is already loaded. Import it in the AppModule only');
    }
  }
 
  staticI forRoot(factory?: Function, deps?: Array<any>): ModuleWithProviders {
    return {
      ngModule: RestangularModule,
      providers: [
        { provide: CONFIG_FACTORY, useValue: factory },
        { provide: Restangular, useFactory: RestangularFactory, deps: [Http, CONFIG_FACTORY, ...(deps || [])] },
      ]
    }
  }
}