我已经在ionic 5中实现了类似于这篇文章中的通用错误消息 Common error
但是当表单加载时,我会出现以下错误:
请告诉我我犯了什么错误...
编辑:
我的HTML类:
<form [formGroup]="transactionForm" (ngSubmit)="SaveTransaction()" novalidate>
<ion-item lines="full">
<ion-label position="floating">Customer Id</ion-label>
<ion-input formControlName="customerNo" type="text" required></ion-input>
</ion-item>
<ar-validation-message [control]="transactionForm.controls.customerNo">
</ar-validation-message>
</form>
编辑:
import { Component, Input } from '@angular/core';
import { FormControl } from '@angular/forms';
import { ValidationService } from 'src/app/services/validation.service';
@Component({
selector: 'ar-validation-message',
template: '<span *ngIf="errorMessage!== null" class="error ion-padding" >{{errorMessage}}</span>'
})
export class ValidationMessageComponent {
@Input() control: FormControl;
constructor(private validationService: ValidationService) {
}
get errorMessage() {
if (this.control.errors) {
for (let propertyName in this.control.errors) {
if (this.control.errors.hasOwnProperty(propertyName) && this.control.touched) {
return this.validationService.getValidatorErrorMessage(propertyName, this.control.errors[propertyName]);
}
}
}
return null;
}
}