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> 

source


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -