0

I am creating a Angular form and while validation, I tried to show message when field is not filled so for that I used ng-for in span tag but I have got error

html - >

<div class="form-group">
    <input type="text" formControlName='fname' placeholder="First Name">
    <span *ngFor="signupForm.control['fname'].haserror(required)"> Enter your Name </span>
</div>

error -

Can't bind to 'ngFor' since it isn't a known property of 'span'. ("m-group">
       <input type="text" formControlName='fname'  placeholder="First Name">
       <span [ERROR ->]*ngFor="signupForm.control['fname'].haserror(required)"> Enter your Name </span>
      </div>  

1 Answer 1

2

USe *ngIf instead of *ngFor

Stackblitz Demo

<span *ngIf="signupForm.get('fname').hasError('required')"> Enter your Name </span>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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