我正在尝试以角度2显示表单中的验证消息?我收到此错误
无法读取未定义的属性'hasError'
我添加了这些行
<div *ngIf="username.hasError('required') && username.touched"
class="error-box"> username is required</div>
<div *ngIf="username.hasError('minlength') && username.touched"
class="error-box"> Minimum password length is 8!</div>
答案 0 :(得分:2)
这应该做你想要的:
<ion-input type="text" ngControl="username" #username="ngForm"></ion-input>
<div *ngIf="username.errors?.required && username.touched"
class="error-box"> username is required</div>
<div *ngIf="username.errors?.minlength && username.touched"
class="error-box"> Minimum password length is 8!</div>