Ajout d'un format custom de la date

This commit is contained in:
Sébastien André
2021-04-22 17:17:32 +02:00
parent 6f7b439e56
commit 0c266c5360
2 changed files with 25 additions and 2 deletions

View File

@@ -69,7 +69,8 @@
<mat-checkbox [(ngModel)]="isSpecial" name="isSpecial">Is a special jump ?</mat-checkbox>
<mat-form-field>
<input matInput [matDatepicker]="beginDateDp" [(ngModel)]="beginDate" name="beginDate" disabled (ngModelChange)="onChangeBeginDate($event)">
<input matInput [matDatepicker]="beginDateDp" [(ngModel)]="beginDate"
name="beginDate" disabled (ngModelChange)="onChangeBeginDate($event)">
<mat-datepicker-toggle matSuffix [for]="beginDateDp"></mat-datepicker-toggle>
<mat-datepicker #beginDateDp disabled="false"></mat-datepicker>
</mat-form-field>

View File

@@ -11,10 +11,32 @@ import { JumpService } from "../../services/jump.service";
import { JumpTypeService } from "../../services/jump-type.service";
import { GearService } from "../../services/gear.service";
import { formatDate } from '@angular/common';
import { DateAdapter, MAT_DATE_FORMATS, NativeDateAdapter } from "@angular/material/core";
export const PICK_FORMATS = {
parse: { dateInput: 'yy MM dd' },
display: {
dateInput: 'yyyy-MM-dd',
monthYearLabel: 'yyyy MMM',
dateA11yLabel: 'yyyy MM dd',
monthYearA11yLabel: 'yyyy MMMM',
}
};
class PickDateAdapter extends NativeDateAdapter {
format(date: Date, displayFormat: Object): string {
return formatDate(date, displayFormat.toString(), "en");
}
}
@Component({
selector: "app-new-jump",
templateUrl: "./new-jump.component.html",
styleUrls: ["./new-jump.component.css"]
styleUrls: ["./new-jump.component.css"],
providers: [
{ provide: DateAdapter, useClass: PickDateAdapter },
{ provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS }
]
})
export class NewJumpComponent implements OnInit {
public beginDate: Date;