Once I have added moment.js
to my project, the next step is to import it in order to use it within components.
import * as moment from 'moment';
In each component, I need to create an empty variable and set up the same configurations in the ngOnInit() function:
export class MyComponent implements OnInit {
moment: any;
ngOnInit() {
moment.locale('ar');
this.moment = moment;
}
}
This process of copy-pasting the code into every component can become repetitive. Is there a way to configure moment.locale()
and other settings just once?