use*_*635 6 locale angular-material angular angular-material-datetimepicker
如果我使用日期选择器
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
并设置一个语言环境
providers: [
{ provide: LOCALE_ID, useValue: 'it-IT' },
{ provide: MAT_DATE_LOCALE, useValue: 'it-IT' }]
Run Code Online (Sandbox Code Playgroud)
如果用户从选择器中选择日期,它会起作用,但如果他在输入框中键入,则日期没有以正确的方式解析。例如:如果用户在框中选择 2018 年 3 月 31 日,则意大利格式为 dd/mm/yyyy,我们会得到“31/03/2018”(没关系)但如果他输入“31/03/2018”,则日期不是验证(但它是一个有效的意大利日期)。如果他输入“03/05/2018”,我们会得到 3 月 5 日而不是 5 月 3 日。是角度材料错误还是我犯了一些错误?
我也试过用“it”代替“it-IT”。
小智 6
根据角度材料示例,您可以使用它
import {Component} from '@angular/core';
import {MAT_MOMENT_DATE_FORMATS, MomentDateAdapter} from '@angular/material-moment-adapter';
import {DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE} from '@angular/material/core';
/** @title Datepicker with different locale */
@Component({
selector: 'datepicker-locale-example',
templateUrl: 'datepicker-locale-example.html',
styleUrls: ['datepicker-locale-example.css'],
providers: [
// The locale would typically be provided on the root module of your application. We do it at
// the component level here, due to limitations of our example generation script.
{provide: MAT_DATE_LOCALE, useValue: 'ja-JP'},
// `MomentDateAdapter` and `MAT_MOMENT_DATE_FORMATS` can be automatically provided by importing
// `MatMomentDateModule` in your applications root module. We provide it at the component level
// here, due to limitations of our example generation script.
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS},
],
})
Run Code Online (Sandbox Code Playgroud)
确保您npm install --save package @angular/material-moment-adapter或yarn add package @angular/material-moment-adapter
| 归档时间: |
|
| 查看次数: |
1163 次 |
| 最近记录: |