How to use Moment.js in Angular 2

It took a bit of a figuring it out, but this is how to use Moment.js in Angular 2 application... Install Moment.js first: npm install moment --save Then, edit systemjs.config.js:...

It took a bit of a figuring it out, but this is how to use Moment.js in Angular 2 application...

Install Moment.js first:

npm install moment --save

2016-09-22_8-32-42

Then, edit **systemjs.config.js:**

Add following into map array:

'moment': 'node_modules/moment'

And following into packages array:

'moment': { defaultExtension: 'js' }

So it looks like this:

2016-09-22_8-34-21

Edit app.component.ts and add in following import:

import * as moment from 'moment/moment';

2016-09-22_9-12-22

Now, you can use Moment.js in your component class, e.g.

2016-09-22_9-16-02

Enjoy!