Search code examples
meteormomentjsangular2-meteor

How to use momentjs npm-package in an angular2-meteor application?


I want to use moment.js library in my angular2-meteor application. For this, I installed the npm package with:

meteor npm install moment --save

Now, in the component, where I want to use this library, I have to import it somehow:

import {???} from 'moment';

But what must be imported here, so I can use it somewhere in the component in the following way:

var foo = moment().format('LLLL');


Solution

  • i have used moment in one of my angular2-meteor app. for using moment.js you should import it like this

    import * as moment from 'moment';
    

    and delcare it and use it like this.

    current_year_header: any;
    date: any;
    this.date = moment();
    this.current_year_header = this.date.format('YYYY');