Sergey Aldoukhov Sergey Aldoukhov - 6 months ago 1697
TypeScript Question

How to use moment.js library in angular 2 typescript app?

I tried to use it with typescript bindings:

npm install moment --save
typings install moment --ambient -- save


import {moment} from 'moment/moment';

And without:

npm install moment --save


var moment = require('moment/moment');

But when I call moment.format(), I get an error.
Should be simple, can anybody provide a command line/import combination that would work?


The following worked for me.

First, install the type definitions for moment.

typings install moment --save

(Note: NOT --ambient)

Then, to work around the lack of a proper export:

import * as moment from 'moment';