How would I get all errors from a form group in angular 2? -
if build form group this:
this.passwordform = this._formbuilder.group({ "previous_password": [this.changepassword.previous_password, validators.compose([validators.required])], "new_password": [this.changepassword.new_password, validators.compose([validators.required,passwordvalidator.validate])], });
how errors form group? i've been doing this:
<form role="form" [formgroup]="passwordform" novalidate (ngsubmit)="submitchangepassword()"> <input [(ngmodel)]="changepassword.previous_password" formcontrolname="previous_password" name="previous_password" type="password" placeholder="previous password" class="form-control" required> <input formcontrolname="new_password" [(ngmodel)]="changepassword.new_password" name="new_password" type="password" placeholder="new password" class="form-control" required> <div *ngif="passwordform.invalid === true && passwordform.controls['new_password'].errors"> <div *ngfor="let line of passwordform.controls['new_password'].errors.message" class="alert alert-danger">{{line}}</div> </div> <div *ngif="passwordform.invalid === true && passwordform.controls['previous_password'].errors"> <div class="alert alert-danger">{{passwordform.controls['previous_password'].errors.message}}</div> </div> </form>
i hoping passwordform.errors
return concatenated list it's null, when passwordform.invalid === true
the way think know if form valid or not doing passwordform.valid , iterate on controls object , find errors of individual form element.
Comments
Post a Comment