Ionic Angular中常见的错误验证消息

4
我已经在ionic 5中实现了类似于这篇文章中的通用错误消息 Common error

但是当表单加载时,我会出现以下错误:

enter image description here

请告诉我我犯了什么错误...

编辑:

我的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;
  }
}

enter image description here


ar-validation-message是什么?它是一个组件吗? - huan feng
请提供需要翻译的英文内容。 - Ajt
你尝试过重启服务器吗? - waseemrakab
同样的代码在 Angular 项目中可以工作,这是另一个 Ionic 项目,同样的代码应该也能工作,对吧? - Ajt
1个回答

2

请检查以下事项:

您是否在 SharedModule 中声明导出了 ValidationMessageComponent?

您是否在使用它的模块中导入SharedModule


谢谢。我有两个网站和移动应用的项目...在网站上,我使用了相同的共享模块,没有问题。但是在Ionic项目中,我直接将组件添加到app.module中,但不起作用...我已经在app.module中声明了它...但是出现错误。 - Ajt

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接