My goal is to compare the values of the password and confirm password inputs. Even when I enter the same value in both fields, an error saying 'Password does not match' still appears.
Component
validate(): boolean {
this.appErrors = [];
if (this.objAppUser.UserName == '') {
this.appErrors.push({ Title: 'User name cannot be blank.' });
}
if (this.objAppUser.LoginName == '') {
this.appErrors.push({ Title: 'Login name cannot be blank.' });
}
if (this.objAppUser.Password == '') {
this.appErrors.push({ Title: 'Password cannot be blank.' });
}
if (this.objAppUser.Password !== this.objAppUser.ConfirmPassword) {
this.appErrors.push({ Title: 'Password does not match.' });
}
if (this.objAppUser.UserCategoryId == 0) {
this.appErrors.push({ Title: 'UserCategory name cannot be blank.' });
}
if (this.appErrors.length > 0) {
return false;
}
else {
return true;
}
}
HTML
<div>
<mat-form-field class="width-size">
<input type="password" matInput [(ngModel)]="objAppUser.password" placeholder="Password" name="passwordCtrl">
</mat-form-field>
</div>
<div>
<mat-form-field class="width-size">
<input type="password" matInput placeholder="Confirm Password" name="confirmpasswordCtrl">
</mat-form-field>
</div>