Angular 2 RC6 Forms control validation message -
<form [formgroup]="registerform" (submit)="onsubmit()"> <label>firstname:</label> <input type="text" formcontrolname="firstname"> <p *ngif="registerform.controls.firstname.errors">this field required!</p> ... is there way make registerform.controls.firstname.errors little bit shorter?
one way define shorter names abstractcontrol properties in form component. in respective component class, add:
firstname: abstractcontrol; and in constructor:
this.firstname = this.registerform.controls['firstname']; now, can access field properties this:
<p *ngif="firstname.errors">this field required!</p>
Comments
Post a Comment