4

I have implemented common error message in ionic 5 similar to this Common error

But when form loads am getting below error

enter image description here

Please let me know what i made the mistake..

EDIT :

My htmls class

<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>

EDIT:

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

4
  • What is ar-validation-message? Is it a component? Commented Nov 28, 2020 at 11:21
  • yes..Updated qustion Commented Nov 28, 2020 at 11:24
  • did you try to restart server? Commented Nov 28, 2020 at 14:48
  • Same code works in angular project..this is another ionic project..same code should work no? Commented Nov 29, 2020 at 1:15

1 Answer 1

2

Check below things:

Have you declared the ValidationMessageComponent in SharedModule and exported it?

Have you imported the SharedModule in the module use it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I have 2 projects for web and mobile...web I have used same in shared module with no issue .but ionic project I have directly added component to app.module which is not working..I have declared it in app.module..but errror showing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.