我目前正在使用登录面板制作应用。但不知何故,我遇到了一个bug。在我的loginController中,我创建了一个登录范围。此外,我检查了空字段或错误的用户名/密码。所有都有CSS边框效果,如绿色表示正确,红色表示错误。
但是当我登录时,两个输入字段在数据正确时变为红色。我在这里错过了什么吗?我的loginController是用AngularJS / Javascript制作的:
$scope.login = function () {
$scope.errorMessg = "";
if ($scope.userinfo.username.length > 0 &&
$scope.userinfo.password.length > 0) {
API.all("user/login").post({
username: $scope.userinfo.username,
password: $scope.userinfo.password
}).then(function() {
if ($scope.userinfo.rememberMe) { //Save in cookie
$cookies.put("cmUsername", $scope.userinfo.username);
$cookies.put("cmPassword", $scope.userinfo.password);
}
$state.go('home.dashboard', {userid: $scope.userinfo.username});
}, function(error) {
switch (error.data.applicationCode) {
case 'U0002':
$scope.errorMessg = gettextCatalog.getString("We don't recognize this accountdata");
break;
default:
$scope.errorMessg = gettextCatalog.getString("Whoops, something went wrong!");
$scope.err = true;
}
if ($cookies.get("cmUsername") && $cookies.get("cmPassword")) {
$cookies.remove("cmUsername");
$cookies.remove("cmPassword");
}
});
} else
$scope.errorMessg = gettextCatalog.getString("Fields can't be empty!");
$scope.err = true;
}
提前感谢任何提示或建议。
答案 0 :(得分:0)
尝试包装最终的else
else {
$scope.errorMessg = gettextCatalog.getString("Fields can't be empty!");
$scope.err = true;
}
$scope.err = true;
始终在该代码的末尾执行,因此可能是您输入字段变为红色的原因。