Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SGStino opened this issue Sep 10, 2018 · 2 comments
Open

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

SGStino opened this issue Sep 10, 2018 · 2 comments

Comments

@SGStino
Copy link

SGStino commented Sep 10, 2018

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
Copy link

anybody has a fix for this?

@mpicciollicmq
Copy link

mpicciollicmq commented Jan 29, 2021

@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);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants