How to use moment js library in angular 2 typescript app

0 votes

I tried to use it with typescript bindings:

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

test.ts:

import {moment} from 'moment/moment';

And without:

npm install moment --save

test.ts:

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?

May 31, 2022 in TypeSript by Logan
• 2,140 points
1,660 views

1 answer to this question.

0 votes

REFERENCE: https://momentjs.com/docs/#/use-it/typescript/

You can install this by using:

npm install --save moment

And in angular, you can import it using:

import * as moment from 'moment';

And this will get you the TypeScript support

 

answered Jun 1, 2022 by Nina
• 3,060 points

Related Questions In TypeSript

0 votes
1 answer

How to use useState hook in React with typescript correctly?

You can set a string type for it Explicit way: const ...READ MORE

answered Aug 3, 2022 in TypeSript by Abhinaya
• 1,160 points
4,227 views
0 votes
1 answer

How to create ES6 Map in Typescript

Refer this as an example this.configs = new ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
836 views
0 votes
1 answer

How to declare and initialize a Dictionary in Typescript

Apparently this doesn't work when passing the ...READ MORE

answered May 31, 2022 in TypeSript by Nina
• 3,060 points
6,496 views
0 votes
1 answer

Is it necessary to learn TypeScript first before going to explore Angular2?

It's not necessary to learn TypeScript but ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
360 views
0 votes
0 answers

ngx-image-cropper imageloaded() not passing any image data to typescript file event method

I'm using ngx-image-cropper to load and crop images. According ...READ MORE

Jul 5, 2022 in TypeSript by Logan
• 2,140 points
1,523 views
0 votes
1 answer

How can I remove a port from url for node app using nginx

If you run your node server on ...READ MORE

answered Apr 10, 2018 in DevOps on Cloud by ajs3033
• 7,300 points
4,030 views
0 votes
1 answer

Docker : multiples linked containers for each customers

Using Docker (specifically Docker Compose) linking containers ...READ MORE

answered Jul 11, 2018 in Docker by Kalgi
• 2,680 points
596 views
0 votes
1 answer

How to use useState hook in React with TypeScript correctly?

Without any initial argument, the type of email and setEmail will ...READ MORE

answered Jun 10, 2022 in TypeSript by Nina
• 3,060 points
1,918 views
0 votes
1 answer

How to use document.getElementById() method in TypeScript?

Typescript will force you to check the ...READ MORE

answered Jun 15, 2022 in TypeSript by Nina
• 3,060 points
6,987 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP