I have got one problem and really don't know how to solve it. Maybe is related to Angular cycles or... The case is next: On the form are two text input fields with button which opens dialog with datepicker. After a date is chosen and confirmed in the dialog, the date is being updated in input field 'From' and the other date 'To' is being calculated and updated in second text field. After these values are shown sometimes I see them properly formatted and sometimes not as if datepipe is not working or the problem is somewhere else but I can't see it.
Below are images from project:
getVisitStartDate() {
const data: DatePickerData = {
minDate: new Date()
};
this.openDateDialog(data).afterClosed().subscribe(
(selectedDate: Date) => {
if (selectedDate) {
this.validFrom.patchValue(selectedDate);
this.calculateEndDate();
}
}
);
}
calculateEndDate() {
if (this.validFrom.value && this.visitQuantity.value) {
this.validTo.patchValue(this.globalService.calculateEndDate(this.validFrom.value, +this.visitQuantity.value));
}
}
get validFrom() {
return this.visitorsFormGroup.get('validFrom');
}
<div class="input-group mb-1">
<input id="valid-from" class="form-control" type="text"
[value]="validFrom.value | date:'dd.MM.yyyy. HH:mm'" formControlName="validFrom">
<div class="input-group-append">
<button class="btn btn-tool" type="button" (click)="getVisitStartDate()"><i
class="fa fa-calendar"></i></button>
</div>
</div>
Some help would be appreciated. Thank you.
Zeljko