Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting minimum Date on Angular validation

Hello guys I'm trying to make a minimum Date value in a Form. I'm using angular and for some reason that doesn't work I'll post my code:

Component:

minDate: Date;

  constructor(private auth: AuthService, private dataService: DataService, private fb: FormBuilder, private router: Router, private matService: MatService) {
    this.dataService.getCompanyCouponResult(this.dataService.CouponIdForEdit).subscribe(res => {
      this.coupon = res;
      this.minDate = this.coupon.startDate;
      console.log(this.minDate);
    })

Output:

edit-coupon.component.ts:28 2014-02-13T22:00:00.000+0000

html:

  New end date:</p>
    <input type="date" formControlName="couponEndDate" min="{{minDate}}" >

now I do get the date, and I'm able to see it in console, but for some reason that doesn't apply on the "min" of couponEndDate. any solution?

like image 716
hindi1991 Avatar asked Jun 11 '26 05:06

hindi1991


1 Answers

You need to use pipes in it. Try with this:

<input type="date" formControlName="couponEndDate" min="{{todate | date:'yyyy-MM-dd'}}">
like image 135
Gaspar Avatar answered Jun 13 '26 19:06

Gaspar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!