In angular material dialog popup i want compare the two dates and if From date is less then To Date i will display the error using
I tried something below
<div class="col">
<mat-form-field>
<mat-label>Last updated Date From</mat-label>
<input matInput [matDatepicker]="updateFromPicker" formControlName="fromUpdatedDateTime">
<mat-datepicker-toggle matSuffix [for]="updateFromPicker"></mat-datepicker-toggle>
<mat-datepicker #updateFromPicker></mat-datepicker>
</mat-form-field>
</div>
<div class="col">
<mat-form-field>
<mat-label>Last updated Date To</mat-label>
<input matInput [matDatepicker]="updateToPicker" formControlName="toUpdatedDateTime" >
<mat-datepicker-toggle matSuffix [for]="updateToPicker"></mat-datepicker-toggle>
<mat-datepicker #updateToPicker></mat-datepicker>
</mat-form-field>
<mat-error *ngIf="filterForm.controls['toUpdatedDateTime'].hasError('incorrect')">To date can not be less than From date</mat-error>
</div>
and in My component file
private intiform() {
this.filterForm = this.formBuilder.group({
selectOnMemberBehalf: [this.transactionFilter.selectOnMemberBehalf],
memberCode: [this.transactionFilter.memberCode],
isPayer: [this.transactionFilter.isPayer],
isPayee: [this.transactionFilter.isPayee],
rtgsReference: [this.transactionFilter.rtgsReference],
counterPartyCode: [this.transactionFilter.counterPartyCode],
transactionStatus: [this.transactionFilter.transactionStatus],
valueDate: [this.transactionFilter.valueDate],
transactionType: [this.transactionFilter.transactionType],
queueStatus: [this.transactionFilter.queueStatus],
fromReceivedDateTime: [this.transactionFilter.fromReceivedDateTime],
toReceivedDateTime: [this.transactionFilter.toReceivedDateTime],
***fromUpdatedDateTime: [this.transactionFilter.fromUpdatedDateTime],
toUpdatedDateTime: [this.transactionFilter.toUpdatedDateTime,[Validators.required,this.validateToDate]],***
payerReference: [this.transactionFilter.payerReference],
amountFrom: [this.transactionFilter.amountFrom],
amountTo: [this.transactionFilter.amountTo]
});
}
validateToDate() {
//How to read form controls here?
//this.filterForm.controls['fromUpdatedDateTime'].setErrors({'incorrect': true});
}
how to access the form controls inside the validateFunction i am getting error
Cannot read property 'filterForm' of undefined