jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
967 stars 121 forks source link

import 'moment-duration-format'; overrides moment.locale('nl') #124

Open SGStino opened 5 years ago

SGStino commented 5 years ago

when importing moment-duration-format in a lazy loaded module component (angular pages) import 'moment-duration-format'; the locale set (moment.locale('nl')) in the constructor of the AppComponent seems to be reset.

If I import moment-duration-format in the AppComponent and not in the Page's Component, the locale doesn't get reset.

sibelius commented 4 years ago

anybody has a fix for this?

mpicciollicmq commented 3 years ago

@sibelius you have to import moment-duration-format before changing the locale.

I import it only once in a service:

import { Injectable } from '@angular/core';
import * as moment from 'moment';
import 'moment-duration-format';

@Injectable({
    providedIn: 'root',
})
export class LanguageService {
    private lang: string;

    constructor( ) {}

    getLang(): string {
        return this.lang;
    }

    setLang(lang: string) {
        this.lang = lang;
        moment.locale(this.lang);
    }
}