<div class="container">
<h1>SignUp Form</h1>
<form>
<div class="form-group" >
<label for="name">Name</label>
<input type="text" class="form-control" [ngClass]="{'red-border':user.name.errors}" [(ngModel)]="user.name" [ngModelOptions]="{standalone: true}" id="name" required >
</div>
<div class="form-group">
<label for="pass">Password</label>
<input type="password" class="form-control" id="pass" [(ngModel)]="user.pass" [ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="cpass">Confirm Password</label>
<input type="password" class="form-control" id="cpass "required [(ngModel)]="user.cpass" [ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="dob">DOB</label>
<input type="date" class="form-control" id="dob" required [(ngModel)]="user.dob"[ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" required [(ngModel)]="user.email" [ngModelOptions]="{standalone: true}">
</div>
<div class="form-group">
<label for="contact">Contact</label>
<input type="text" class="form-control" id="contact" required [(ngModel)]="user.contact" [ngModelOptions]="{standalone: true}">
</div>
<button type="button" (click)="validateUser(user)" class="btn btn-success" >Submit</button>
</form>
</div>
我对Angle 2还是陌生的,我在输入标签中尝试了必填属性,但无法正常工作。我也想改变输入错误时的颜色。我试过了,但是我不知道该怎么做。这是代码。
答案 0 :(得分:0)
为您的输入字段输入名称,例如name="name"
,然后尝试使用此user.name.errors.required
而不是user.name.errors