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

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

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

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -