angularjs - cannot read property 'validator' of undefined in angular 2? -


how validate form in angular2? getting error.

https://plnkr.co/edit/slhyswt0mjxklogk1kfo?p=preview

<ion-navbar *navbar>   <ion-title>     ionic 2   </ion-title> </ion-navbar>  <ion-content class="has-header">     <form [ngformmodel]="loginform" (submit)="login($event)">             <ion-input stacked-label>                 <ion-label>username</ion-label>                 <input type="text" ngcontrol="username">             </ion-input>              <ion-input stacked-label>                 <ion-label>password</ion-label>                 <input type="password" ngcontrol="password">             </ion-input>              <div padding>                 <button block type="submit" [disabled]="!loginform.valid">login</button>             </div>         </form> </ion-content> 

the error

typeerror: cannot read property 'validator' of undefined     @ ngformmodel.ngonchanges (https://code.angularjs.org/2.0.0-beta.15/angular2.dev.js:17240:73)     @ abstractchangedetector.changedetector_formclass_0.detectchangesinrecordsinternal (viewfactory_formclass:86:59) 

i'm not familiar ionic2, may going on i'm not aware of. however, looks aren't declaring or initializing form controls in formclass. maybe try this:

export class formclass {    loginform: controlgroup;    constructor(private fb: formbuilder){     this.loginform = this.fb.group({       'username': ['', validators.required],       'password': ['', validators.required]     });   }  } 

you need define login method in formclass handle (submit) binding you've defined.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -