title: Angular 2 Library config
body: <p>Currently I am trying to create my first Angular 2 library, a translate pipe. Right now I am trying to make the developer able to insert an object with translations into the module so the pipe can use it.</p>
  
  <p>How can I insert some sort of config/object into my library so all my components, pipes and services can use it?</p>
  
  <p>My library looks like:</p>
  
  <p>index.ts</p>
  
  <pre><code>import { NgModule, ModuleWithProviders } from '@angular/core';
  import { CommonModule } from '@angular/common';
  
  import { TranslatePipe } from './translate.pipe';
  
  export * from './translate.pipe';
  
  @NgModule({
      imports: [
          CommonModule
      ],
      declarations: [
          TranslatePipe
      ],
      exports: [
          TranslatePipe
      ]
  })
  export class TranslateModule
  {
      static forRoot(): ModuleWithProviders
      {
          return {
              ngModule: TranslateModule,
              providers: []
          };
      }
  }
  </code></pre>
  
  <p>translate.pipe.ts</p>
  
  <pre><code>import { Injectable, PipeTransform, Pipe } from '@angular/core';
  
  @Pipe({
      name: 'translate'
  })
  
  @Injectable()
  
  export class TranslatePipe implements PipeTransform
  {
  
      public translations: any = null;
  
      constructor ()
      {
          this.translations = {};
      }
  
      transform(key: string): string
      {
          let translation = key;
  
          if (key in this.translations) translation = this.translations[key];
  
          return translation;
      }
  }
  </code></pre>
  
  <p>My testing project:</p>
  
  <pre><code>import { BrowserModule } from '@angular/platform-browser';
  import { NgModule } from '@angular/core';
  import { FormsModule } from '@angular/forms';
  import { HttpModule } from '@angular/http';
  
  import { AppComponent } from './app.component';
  
  import { TranslateModule } from 'translate-pipe';
  
  @NgModule({
      declarations: [
          AppComponent,
          TranslateModule
      ],
      imports: [
          BrowserModule,
          FormsModule,
          HttpModule
      ],
      providers: [
          TranslateModule
      ],
      bootstrap: [AppComponent]
  })
  export class AppModule { }
  </code></pre>