![](/img/trans.png)
[英]How to know when value of an ng-read text input has changed AngularJS?
[英]How to tell angularjs form that the input value has changed
我通過使用angularjs建立了一個注冊。 提交過程正常。 然后,我想對檢查電子郵件是否已經注冊進行驗證。 如果存在,請顯示錯誤消息,通知該電子郵件存在。 我面臨的問題是,當用戶更改電子郵件地址時,提交的電子郵件仍然是前一封電子郵件。 如何告訴angular輸入值已更改並提交新插入的值。
我的注冊表格
<div ng-controller="signupController">
<form ng-submit="doSignup()">
<h2 class="form-signin-heading">Sign Up</h2>
<div class="login-wrap">
<input type="text" name="email" class="form-control" autofocus="" ng-model="formData.email">
<span class="text-danger">{{ emailExistError }}</span>
<input type="password" name="password" class="form-control" placeholder="Password" ng-model="formData.password">
<input type="password" name="password_conf" class="form-control" placeholder="">
<button class="btn btn-lg btn-login btn-block" type="submit">Sign Up</button>
</div>
</form>
</div>
app.js
angular.module('myApp', ['ngRoute', 'ngSanitize'])
.controller('mainController', function ($scope, $http) {
})
.controller('signupController', function ($scope, $http,$window) {
$scope.formData = {};
$scope.doSignup = function () {
$http({
method: 'post',
url: 'signup.php',
data: $.param($scope.formData),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function (data) {
$scope.login = data;
if (data.status == 'ok') {
$('#successModal').modal('show');
}
else if (data.status == 'email exist'){
$scope.emailExistError = 'Email exist. Use different email';
}
else {
$('#failedModal').modal('show');
}
})
}
})
嘗試
$watch('email',function(newVal,oldVal){
if(newVal!=oldVal){
$scope.doSignup();
}});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.