Home > Software engineering >  ngb date picker disable past date angular
ngb date picker disable past date angular

Time:10-15

I am using ngb date picker for my forms. I am using below code for it. Its working well. I need to disable past date disable (user can select current date onwards).

  <input class="form-control ngbfield" (dateSelect)="loadCheckinTime(checkin.checkdate)"
                                placeholder="yyyy-mm-dd" required name="checkdate" [readonly]="true" #vl="ngModel"
                                [(ngModel)]="checkin.checkdate" ngbDatepicker [markDisabled]="isDisabled"
                                #d1="ngbDatepicker" required>
                            <div class="input-group-append">
                                <button class="btn btn-outline-secondary fa fa-calendar" (click)="d1.toggle()"
                                    type="button"></button>
                            </div>

How i disable past date.

CodePudding user response:

You can use input binding [minDate]

  <input class="form-control ngbfield" [minDate]="minDate"(dateSelect)="loadCheckinTime(checkin.checkdate)"
                            placeholder="yyyy-mm-dd" required name="checkdate" [readonly]="true" #vl="ngModel"
                            [(ngModel)]="checkin.checkdate" ngbDatepicker 
                            #d1="ngbDatepicker" required>

ts File

minDate : any;

constructor() {
  const todayDate = new Date();
  this.minDate = {
    year: todayDate.getFullYear(),
    month: todayDate.getMonth()   1,
    day: todayDate.getDate()
  };
}
                       
  • Related