我們如何設定日歷的最小日期,最小值是從當前日期起 2 天。所以如果今天是 27,那么當前或最小日期應該是 29,因為從現在起 2 天后是 29。有什么想法嗎?謝謝。

#html代碼
<mat-form-field class="example-full-width">
<input matInput #input="ngModel" [(ngModel)]="date" [min]="minDate" [max]="maxDate" [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
<mat-error *ngIf="input.hasError('matDatepickerMax')">Date should be inferior</mat-error>
</mat-form-field>
#ts 代碼
import {Component} from '@angular/core';
/** @title Datepicker with min & max validation */
@Component({
selector: 'datepicker-min-max-example',
templateUrl: 'datepicker-min-max-example.html',
styleUrls: ['datepicker-min-max-example.css'],
})
export class DatepickerMinMaxExample {
minDate = new Date();
}
uj5u.com熱心網友回復:
嘗試:
import {Component} from '@angular/core';
/** @title Datepicker with min & max validation */
@Component({
selector: 'datepicker-min-max-example',
templateUrl: 'datepicker-min-max-example.html',
styleUrls: ['datepicker-min-max-example.css'],
})
export class DatepickerMinMaxExample {
minDate = (new Date()).setDate(new Date().getDate() 2);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/465627.html
標籤:javascript 有角度的 打字稿
上一篇:附加到部分超出部分
