How can I manually set an Angular form field as invalid?

Forums AngularHow can I manually set an Angular form field as invalid?
Staff asked 3 years ago

Answers (1)

Add Answer
Nayan Raval Marked As Accepted
Staff answered 3 years ago

In component,

formData.form.controls['email'].setErrors({'incorrect': true});

and in HTML:

<input mdInput placeholder="Email" type="email" name="email" required [(ngModel)]="email"  #email="ngModel">
<div *ngIf="!email.valid">{{email.errors| json}}</div>

 

 

Subscribe

Select Categories