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:
1 | npm install moment --save |
Then, edit systemjs.config.js:
Add following into map array:
1 | 'moment': 'node_modules/moment' |
And following into packages array:
1 | 'moment': { defaultExtension: 'js' } |
So it looks like this:
Edit app.component.ts and add in following import:
1 | import * as moment from 'moment/moment'; |
Now, you can use Moment.js in your component class, e.g.
Enjoy!
Facebook Comments