Angular 2 form validation not working -


i have angular 2 application (rc.4) , i'm having issues form validation.

i have below form code in template.

<div class='modal'>     <form #modalform='ngform'>       <div class='heading'>         <h4>{{_title}}</h4>         <div class='close-icon' (click)='close()'></div>       </div>       <div class='body'>         <input type='text' name='projectname' [(ngmodel)]='projectname' required placeholder='give project name...' id='focusonme'>       </div>       <div class='controls'>         <button class='btn btn-secondary' (click)='close()'>cancel</button>         <button type='submit' class='btn' (click)='sendaction()' [disabled]='!modalform.form.valid'>{{_action}}</button>       </div>     </form>   </div> 

as can see name form element , set ngform , on input include required attribute , on submit button [disabled]=!modalform.form.valid reason form flagged valid when required input empty. missing here?

for angular 2 rc 4:

you missing part tell form "projectname" input should part of form validation. add "ngcontrol='inputid'":

<input type='text' name='projectname' ngcontrol="projectname" [(ngmodel)]='projectname' required placeholder='give project name...' id='focusonme'> 

for angular 2.0 final:

  1. add [formgrooup] form:

<form [formgroup]="modalform">

  1. add "formcontrolname" control:

<input type='text' name='projectname' formcontrolname="projectname" [(ngmodel)]='projectname' required placeholder='give project name...' id='focusonme'>


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -