Making moment injectable in angular2
<p>I would like to make moment to be injectable through out my app.<br>
I just started learning ng2 and couldn't find this type of usage in the docs.<br>
Here is what I have in my <code>app.module.ts</code>:  </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 * as moment from 'moment';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [{provide: 'moment', useValue: moment}],
  bootstrap: [AppComponent]
})
export class AppModule {
}
</code></pre>

<p>and here is the component:  </p>

<pre><code>import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})


export class AppComponent {
  title = 'app works!';

  constructor(private moment) {
    this.title += this.moment;
  }
}
</code></pre>

<p>there is this error:  </p>

<pre><code>Uncaught Error: Can't resolve all parameters for AppComponent:
</code></pre>

<p>How should this be done correctly?</p>

<p><strong>UPDATED MODULE</strong>  </p>

<pre><code>const moment = new OpaqueToken('moment');

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [{provide: moment, useValue: moment}],
  bootstrap: [AppComponent]
})

export class AppModule {
}
</code></pre>

<p><strong>UPDATED COMPONENT</strong>  </p>

<pre><code>import { Component } from '@angular/core';
import * as moment from 'moment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})


export class AppComponent {
  title = 'app works!';

  constructor(private moment: moment) {
    this.title += this.moment()
  }
}
</code></pre>

<p>There is an error on this line <code>constructor(private moment: moment)</code> which tells that: <code>Cannot find name 'moment'.</code></p>