angularjs - angular 2 form validation giving undefined error message -
i followed angular 2 tutorial , tried implement validation in angular 2 form. see code:
<form #loginform="ngform" (ngsubmit)="login()"> <div> <label for="email">email:</label> <input type="text" id="email" name="email" required minlength="4" maxlength="24" [(ngmodel)]="emailfield" #name="ngmodel" /> <div *ngif="email?.errors && (email?.dirty || email?.touched)" class="alert alert-danger"> <div [hidden]="!email.errors.required"> email required </div> <div [hidden]="!email.errors.minlength"> email must @ least 4 characters long. </div> <div [hidden]="!email.errors.maxlength"> name cannot more 24 characters long. </div> </div> </div> <div> <label>password:</label><input type="password" name="password" [(ngmodel)]="passwordfield" /> </div> <div> <button [disabled]="!loginform.form.valid" type="submit">submit</button> </div> </form>
the problem getting error code :
error error: uncaught (in promise): typeerror: cannot read property 'errors' of undefined
i tried implement in tutorial on official site: https://angular.io/docs/ts/latest/cookbook/form-validation.html#!#template1
the answer( george k ) accidentally wrote #name="ngmodel"
instead of #email="ngmodel"
Comments
Post a Comment