Add moment to angular 2 (angular cli)

To install third party library in the newest version of angular-cli is just made simpler. (The webpack version, not systemjs one).

Go to your angular-cli.json on your project root and configure it like,

{
  ...
  "apps": [
     ...
     "scripts": [
        "../node_modules/moment/min/moment.min.js"
     ]
     ...
  ]
  ...
}

Then finally, in your any.component.ts you can import it like this,

import { Component, OnInit } from '@angular/core';
import * as moment from 'moment';

@Component({
    selector: '[id=home]',
    templateUrl: './home.component.html',
    styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {
    constructor() { }

    ngOnInit () {
        console.log('today is', moment());
    }
}

This thread is a little old but this is what I needed. Moment now comes with a type definition file and @types/moment is now deprecated in favor of this new file. In order to have moment work with other libraries which extend type definitions from moment like fullcallendar, you'll also need to override the default module resolution in your tsconfig.app.json

"compilerOptions": {
    ...
    "paths": {
        "moment": [
          "../node_modules/moment/moment.d.ts", 
          "../node_modules/moment/min/moment.min.js"
        ]
    },
},

You'll also want to update your angular.json build section to include moment:

 "build": {
      ...,
      "options": {
        ...
        "scripts": [ "node_modules/moment/min/moment.min.js"]
 },