Javascript 切换isn';t换回来,然后span ng bind赢了';t更新到指定的文本
我正在尝试创建一个登录页面,当单击登录时,它将变为登录。。。。如果登录不正确,则“登录”按钮返回“登录”,并在下面显示错误消息。发生的情况是,单击“登录”后,登录。。。。即使输入了错误的密码,也要留下来,直到我集中输入电子邮件后,错误消息才会更新。非常感谢。 Html登录文件Javascript 切换isn';t换回来,然后span ng bind赢了';t更新到指定的文本,javascript,html,angularjs,ionic-framework,Javascript,Html,Angularjs,Ionic Framework,我正在尝试创建一个登录页面,当单击登录时,它将变为登录。。。。如果登录不正确,则“登录”按钮返回“登录”,并在下面显示错误消息。发生的情况是,单击“登录”后,登录。。。。即使输入了错误的密码,也要留下来,直到我集中输入电子邮件后,错误消息才会更新。非常感谢。 Html登录文件 <ion-view title="Login" id="page6"> <ion-content padding="true" class="has-header"> <form
<ion-view title="Login" id="page6">
<ion-content padding="true" class="has-header">
<form id="login-form4" class="list">
<ion-list id="login-list2">
<label class="item item-input" id="login-input10">
<span class="input-label">Username/Email</span>
<input type="text" ng-model="UserInfo.email" placeholder="">
</label>
<label class="item item-input" id="login-input11">
<span class="input-label">Password</span>
<input type="password" ng-model="UserInfo.password" placeholder="">
</label>
</ion-list>
<div class="spacer" style="height: 40px;"></div>
<button id="login-button2" ng-click="login();login = !login" class="button button-positive button-block">
<span ng-show="login"> Log in</span>
<span ng-hide="login">Logging in....</span>
</button>
<a ui-sref="signup" id="login-button3" class="button button-positive button-block button-clear">Or create an account</a>
</form>
<span ng-bind="errorText"><font color="red"></font></span>
</ion-content>
</ion-view>
DOM将仅在运行摘要循环后更新。如果您自己不调用它,则只有在触发事件(如单击电子邮件文本框)时,才会发生此事件 要手动运行摘要循环,请在设置
$scope.errorText
$rootScope.Scope#$apply是,修复了错误消息谢谢,但是如果您想登录,登录按钮仍然停留在“登录…”位置。。。。要在显示错误消息时消失,应使用ng show而不是ng hide。按照现在的方式,在错误消息之后,$scope.login被设置为false,因此ng hide=false,这意味着它没有隐藏,这意味着它确实显示了。还要确保在将$scope.login设置为true后调用$apply()
.controller('loginCtrl', ['$scope', '$stateParams', 'md5', 'Userid', '$state',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,md5,Userid,$state) {
$scope.UserInfo = {};
$scope.login = true;
$scope.login =function(){
var client = new WindowsAzure.MobileServiceClient('URL');
if ($scope.UserInfo.password == null){
$scope.UserInfo.password = "fa";
}
console.log($scope.UserInfo.password);
var query = client.getTable('USERID')
.where({ Email: $scope.UserInfo.email, Password: md5.createHash($scope.UserInfo.password) })
.read()
.done(function(results) {
if(results[0] == undefined)
{
console.log("undefined");
$scope.errorText = "Error: Wrong Username Passowrd";
$scope.login = false;
}
else
{
Userid.setJson(results[0].id);
$state.go('tabsController.qRCode');
}
}, function(error) {
console.log('an error occurred while checking login:');
console.dir(error);
});
$scope.UserInfo.password = "";
};
}])