如何验证密码和确认密码必须相同,否则不提交。
<div class="col-md-6 col-md-offset-3">
<h2>Change Password</h2>
<form name="form1" (ngSubmit)="f.form.valid && cpass()" #f="ngForm" novalidate>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !password.valid }">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" [(ngModel)]="model.password" #password="ngModel" required />
<div *ngIf="f.submitted && !password.valid" class="help-block">Password is required</div>
</div>
<div class="form-group" [ngClass]="{ 'has-error': f.submitted && !confirm-password.valid }">
<label for="confirm-password">Confirm Password</label>
<input type="password" class="form-control" name="confirm-password" [(ngModel)]="model.confirm-password" #password="ngModel" required />
<div *ngIf="f.submitted && !confirm-password.valid" class="help-block">Password is required</div>
</div>
<div class="form-group">
<button class="btn btn-primary">Save</button>
<a [routerLink]="['/home']" class="btn btn-link">Cancel</a>
</div>
</form>
</div>
答案 0 :(得分:0)
您需要实现自定义验证程序来执行确认密码
之类的操作这是一篇关于这个主题的好文章