followed below steps to install and use moment:
npm install moment --save
In app.component.ts file:
import * as moment from 'moment';
export class AppComponent{
currentDate = moment();
Also added below code in angular.json as per this article:
"scripts": ["./node_modules/moment/min/moment.min.js"]
I get:
TypeError: moment is not a function
Please check repro demo
If you know why I am getting this error please assist.
import is fine:
import * as moment from 'moment';
You also need to install the type definition so that the typescript compiler can resolve the types specific to moment.js:
npm install @types/moment
import * as temp from 'moment'; const moment = temp["default"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With