这是我使用Angularjs5进行客户端验证的代码。
<form class="col s12 white" #userRegistrationForm="ngForm">
<div class="row">
<div class="input-field col s6">
<input class="validate" type="text" name="UserName" #UserName="ngModel" [(ngModel)]="user.UserName" required>
<label data-error="Required Field!">UserName</label>
</div>
<div class="input-field col s6">
<input type="text" name="Password" #Password="ngModel" [(ngModel)]="user.Password" required>
<label>Password</label>
</div>
<div class="input-field col s6">
<input type="text" name="Email" #Email="ngModel" [(ngModel)]="user.Email">
<label>Email</label>
</div>
<div class="input-field col s6">
<input type="text" name="FirstName" #FirstName="ngModel" [(ngModel)]="user.FirstName">
<label>FirstName</label>
</div>
<div class="input-field col s6">
<input type="text" name="LastName" #LastName="ngModel" [(ngModel)]="user.LastName">
<label>LastName</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<button class="btn-large btn-submit" type="submit">Submit</button>
</div>
</div>
</form>
验证失败时没有收到错误消息。没有人请给出解决方案。
提前致谢。
答案 0 :(得分:0)
试试这个
<label *ngIf="UserName.errors.required">Required Field!</label>
在此处查看有关如何使用角度表单验证的文档: