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:

2016-09-22_8-32-42

Then, edit systemjs.config.js:

Add following into map array:

And following into packages array:

So it looks like this:

2016-09-22_8-34-21

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

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!

(Visited 1,756 times in last 30 days)

Comments

comments