在Angular 4中,可以使用Angular Material库中的MatDatepicker来实现日期选择器,并且可以自定义日期格式。要显示日期格式为MM/DD/YYYY,可以按照以下步骤进行设置:
npm install @angular/material @angular/cdk @angular/animations
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatInputModule } from '@angular/material/input';
import { MatNativeDateModule } from '@angular/material/core';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
MatDatepickerModule,
MatInputModule,
MatNativeDateModule
],
declarations: [],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
::ng-deep .mat-datepicker-content {
.mat-calendar-body-cell-content {
white-space: nowrap;
}
}
::ng-deep .mat-calendar-body-cell-content span {
display: none;
}
::ng-deep .mat-calendar-body-cell-content::after {
content: attr(aria-label);
display: block;
white-space: nowrap;
}
通过以上步骤,您将能够在Angular 4中使用自定义日期格式MM/DD/YYYY来显示日期选择器。