Minimum input date value should be today

Asked

Viewed 99 times

1

I have a date type input, and I need it not possible to select date that is not from today back, I tried that way, but I did not have much success:

HTML:

<input [(ngModel)]="atv.dataini" type="date" class="form-control" #one min="{{this.today}}">

TYPESCRIPT:

today = this.dNow.getFullYear() + '-0' + (this.dNow.getMonth() + 1) + '-0' + this.dNow.getDate();

also tried that way:

HTML:

<input [(ngModel)]="atv.dataini" type="date" class="form-control" #one min="{{this.tdNow}}">

TYPESCRIPT:

dNow = this.formatDate(new Date());

formatDate(date) {
    let result = date.split('-').reverse().join('/');
    return result
}

1 answer

-2

One simple way is to capture this data in the atv.dataini model and then check it against today’s date and if it is not desired to raise an error for the user

Browser other questions tagged

You are not signed in. Login or sign up in order to post.