我遇到了 angular ui-utils 的问题,特别是 ui-validate。我正在尝试向用户提供密码更改表单并要求“新密码”和“确认新密码”匹配,这里:
<table class="table">
<form>
{{!!passwordForm.newPassword2.$error.validator}}
<tr>
<th>Current password: </th>
<td><input type="text" name="currentPassword" ng-model="passwordForm.currentPassword"></td>
</tr>
<tr>
<th>New password: </th>
<td><input type="password" name="newPassword" ng-model="passwordForm.newPassword"></td>
</tr>
<tr>
<th>Confirm new password:</th>
<td><input type="password" name="newPassword2" ng-model="passwordForm.newPassword2" ui-validate=" '$value==passwordForm.newPassword' " ui-validate-watch=" 'passwordForm.newPassword' "></td>
</tr>
<tr>
<td/>
<td>
<button type="button" ng-click="sendChangePassword()" ng-disabled="passwordForm.newPassword2.$error.validator" class="btn btn-primary">Save</button>
</td>
</tr>
</form>
</table>
在我的控制器中我有
$scope.passwordForm = {
currentPassword: "",
newPassword: "",
newPassword2: ""
};
问题是,无论是否匹配newPassword
,newPassword2
保存按钮都会保持启用状态并{{!!passwordForm.newPassword2.$error.validator}}
评估为假。
我已经浏览了几个 stackoverflow 线程和其他来源,但我只是无法弄清楚我的代码有什么问题。任何帮助,将不胜感激。