Reputation: 1
I would like to change my endDate same as startDate on date picker when I change startDate but when I create event on startDate button and change Date on startDate it didn't work (I use date picker from CoreUI) here is my example code
If I change startDate so endEnd will change to
// startDate
<div>
<small>{{lang.FromDate}}</small>
<c-date-picker [(date)]="startDate" [ranges]="customRanges"
(ngModelChange)="onDateChange($event)"></c-date-picker>
</div>
my function
onDateChange(date: any) {
// Logic to handle the event when a new date is selected
console.log("Date selected:", date);
}
I try to test print the value but don't have anything in consloe.log
(but I try another tag not date picker is work).
endDate
change when we change startDate
Upvotes: -1
Views: 90
Reputation: 57929
if you use as variables "startDate" and "endDate" change the "endDate" variable. Remember, in Angular we change variables and this variables are showed in the .html automatically thanks binding
<div>
<small>{{lang.FromDate}}</small>
<!--see that you use ngModel--->
<c-date-picker [(ngModel)]="startDate" [ranges]="customRanges"
(ngModelChange)="onDateChange($event)"></c-date-picker>
</div>
<div>
<small>{{lang.ToDate}}</small>
<!--see that you use ngModel--->
<c-date-picker [(ngModel)]="endDate" [ranges]="customRanges"></c-date-picker>
</div>
startDate:any=null; //you declare two variables
endDate:any=null;
onDateChange(date:any) //in change you compare the two variables
{
if (this.endDate<date)
this.endDate=date
}
````
Upvotes: 0
Reputation: 1
Instead of ngModelChange
, please try using dateChange
. It is the default method provided in their official document. I have tried it, it works.
Upvotes: -1