[英]Angular Material 2 - MatDatePicker Error - 'Must import MatNativeDateModule/MatMomentDateModule'
[英]Angular Material MatMomentDateModule imports all Moment locales
我將 MatMomentDateModule 用於 Angular Material 的 matDatePicker 組件。 但這會導入 Moment.js 的所有語言環境,即使我只需要一個:
有沒有辦法告訴它只導入我需要的語言環境?
在我的模塊中,我像這樣導入它:
import { MatDatepickerModule } from '@angular/material';
import { MatMomentDateModule } from '@angular/material-moment-adapter';
@NgModule({
declarations: [],
imports: [
...
MatDatepickerModule,
MatMomentDateModule,
...
],
exports: [
...
MatDatepickerModule,
MatMomentDateModule,
...
]
})
export class MaterialModule {}
您可以嘗試在 app.module.ts 的 Providers 數組中指定它?
@NgModule({
providers: [
{provide: MAT_DATE_LOCALE, useValue: 'en-GB'},
],
})
export class MyApp {}
見鏈接: https://material.angular.io/components/datepicker/overview#setting-the-locale-code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.