【发布时间】:2020-06-04 13:07:18
【问题描述】:
在弹出的角度材料对话框中,我想比较两个日期,如果从日期小于到日期,我将使用
显示错误我在下面尝试了一些东西
<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>
在我的组件文件中
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});
}
如何访问 validateFunction 中的表单控件 我收到错误
无法读取未定义的属性“filterForm”
【问题讨论】: