Вот как я решил это, если у кого-то такая же проблема. Это позволяет вводить даты через +1 (завтра), -1 (вчера), et c.
Я создал директиву ...
export class DateEntryShortcutsDirective {
// form control bound to datepicker input
@Input() control: FormControl;
constructor() {}
// listen for change events on the datepicker input
@HostListener('change', ['$event']) onChange(event: any) {
this.setDate(event.target.value);
}
setDate(data) {
if (typeof data === 'string' && data.length) {
// if values begins with '+'
if (data.substring(0, 1) === '+') {
// get current date and advance by however many days requested
const dayDiff = +data.substring(1);
const date = new Date(
new Date().getTime() + dayDiff * 24 * 60 * 60 * 1000
);
// set the control value to date
if (this.control) {
this.control.setValue(date);
}
} else if (data.substring(0, 1) === '-') {
// if value begins with '-'
// get current day and subtract days
const dayDiff = +data.substring(1);
const date = new Date(
new Date().getTime() - dayDiff * 24 * 60 * 60 * 1000
);
// set control to date
if (this.control) {
this.control.setValue(date);
}
}
}
}
}
Директива тогда используется так ...
<mat-form-field class="mat-form-field date items">
<mat-label>Deliver NLT</mat-label>
<input
tabindex="{{ 80 + index * 1500 }}"
matInput
autocomplete="off"
[matDatepicker]="receiverNLTDate"
placeholder="Date NLT"
formControlName="receiverNoLaterThanDate"
(dateChange)="onReceiverNoLaterThanChanges()"
[min]="
this.data.reference.freightUnits[this.index]
.receiverRequestedDeliveryDate
"
appDateEntryShortcuts
[control]="receiverNoLaterThanDate"
/>
<mat-datepicker-toggle
matSuffix
[for]="receiverNLTDate"
></mat-datepicker-toggle>
<mat-datepicker #receiverNLTDate></mat-datepicker>