¿Cómo establecemos la fecha mínima para un calendario? El mínimo es de 2 días a partir de la fecha actual. Entonces, si hoy es el 27, entonces la fecha actual o mínima debería ser el 29, ya que dentro de 2 días es el 29. ¿Alguna idea, muchachos? Gracias.
#código 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>código #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(); }Probar:
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); }