8

According to the documentation https://material.angular.io/components/datepicker/overview here to set the locale code to one you want you provide it by putting

providers: [
    {provide: MAT_DATE_LOCALE, useValue: 'en-GB'},
]

But then my app won't compile as it tells me it cannot find the name MAT_DATE_LOCALE. Am I missing something here as in I have to define it myself? Though, I can't think of where to put it as it's all in the module class.

5
  • are you on the latest version (beta12)? Commented Oct 26, 2017 at 12:22
  • Yes, I am on the latest version. Commented Oct 26, 2017 at 13:09
  • 4
    Do import { MAT_DATE_LOCALE } from '@angular/material'; at the top of the file. Commented Oct 28, 2017 at 7:36
  • So this worked actually. Dunno how to your comment as the answer though. Commented Nov 5, 2017 at 11:34
  • @user276648 thanks. They should write that on the documentation. Commented Aug 7, 2018 at 18:00

6 Answers 6

17

In Angular 9 do the import:

 { MAT_DATE_LOCALE } from '@angular/material/core';

I suppose that in the import must be entered specified path import. Optimization stuff.

Sorry for my english.

From Angular 9, no component can be imported through @angular/material. You are to use the individual secondary entry-points, such as @angular/material/button.

Top New Features of Angular 9

Sign up to request clarification or add additional context in comments.

Comments

12

To use MAT_DATE_LOCALE, it has to be imported explicitly like below

import { MAT_DATE_LOCALE } from '@angular/material';

Please note that MAT_DATE_LOCALE should not be added to imports: [ ] array.

Comments

6

When you upgrade your project dependancies from old version to new version some modules are moved into different namespaces, so you need to manually change them

i am using angular 9.1.2

I've used this

import { MAT_DATE_LOCALE } from '@angular/material/core';

instead of

import { MAT_DATE_LOCALE } from '@angular/material';

2 Comments

Thanks, this is more expressive explanation. Could I ask where is the best place to ascertain these alterations for similar moved imports as there are a number of these changes after upgrading - where does it tell you this in the documentation?
steps that i follow: 1. Debug the code for error message 2. google the error message
3

In my case I imported this

import { MatInputModule, MatNativeDateModule, MAT_DATE_LOCALE } from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';

and in my material.module.ts I do

imports: [
  ....
  MatDatepickerModule,
  MatNativeDateModule
],
exports: [
   ...
   MatDatepickerModule,
   MatNativeDateModule
],
providers: [
   {provide: MAT_DATE_LOCALE, useValue: 'pt-BR'},
],

in this whay its work

Comments

0

make sure you are changing the correct file.

src\app\material\material.module.ts

import {MAT_DATE_LOCALE} from '@angular/material/core';
...
@NgModule({
  providers: [
{provide: MAT_DATE_LOCALE, useValue: 'en-GB'},
 ],

Comments

-1

Had similiar issues, this is what you'll do. import {MatNativeDateModule} from '@angular/material the on your @ngModule({ import: [MatNativeDateModule] }) this should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.