一个简单的问题我的表单上有两个输入,如下所示:
<input
ng-keyup="validPasswordCheck()"
ng-class="{'ng-invalid':!validPassword}"
type="password" id="password"
ng-model="registerCredentials.password"
placeholder="Password">
<input
ng-keyup="validPasswordCheck()"
ng-class="{'ng-invalid':!validPassword}"
type="password" id="password"
ng-model="registerCredentials.repeatPassword"
placeholder="Repeat Password">
我有一个看起来像这样的控制器:
$ scope.registerCredentials = { 用户名: '', 密码:'', 重复输入密码: '' };
$scope.validPasswordCheck = function() {
$scope.validPassword = registerCredentials.password === registerCredentials.repeatPassword;
}
我试图这样做,当密码不匹配时,他们都有类ng-invalid,当他们匹配时,他们不应该有类。我正在尝试刷新检查以确定它在每个keyup(ng-keyup指令)上都有效。这似乎根本不起作用,它总是无效的。
非常感谢任何帮助。
答案 0 :(得分:2)
您在模型变量前面缺少$scope
:
$scope.validPassword = $scope.registerCredentials.password === $scope.registerCredentials.repeatPassword;