这里奇怪的错误。我有这个表格:
<form name="newaccount" id="newaccount" ng-submit="doSubmit()">
<label>username</label>
<input name="username" type="text" required ng-model="username">
<span ui-toggle="username.length > 15">Too long!</span>
<label>name</label>
<input name="name" type="text" required ng-model="name">
<label>e-mail</label>
<input name="email" type="email" required ng-model="email" ui-validate>
<label>password</label>
<input name="password" type="password" required ng-model="password" ui-validate>
<div style="text-align: center;"><br>
<input type="submit"></div>
</form>
而这个控制器:
$scope.username = "f";
$scope.password = "f";
$scope.email = "f";
$scope.name = "f";
$scope.doSubmit = function(){
//Transition to progress view
$scope.showLoginForm = false;
$scope.showCreateForm = false;
$scope.showLoading = true;
$scope.resultSuccess = false;
$scope.showResult = false;
$scope.loadingMessage = "Creating account...";
$scope.resultReason = "Success!";
//Send POST
$http({
method: 'POST',
url: "php/createaccount.php",
data: {
"username": $scope.username,
"password": $scope.password,
"name": $scope.name,
"email": $scope.email
}}
).success(function (data, status, headers, config) {
$scope.showLoading = false;
$scope.showResult = true;
$scope.resultSuccess = data === "success";
if($scope.resultSuccess){
$scope.resultReason = "Account created successfully!";
}else{
$scope.resultReason = data;
}
}).error(function (data, status, headers, config) {
$scope.showLoading = false;
$scope.showResult = true;
$scope.resultSuccess = false;
$scope.resultReason = data;
});
};
正如预期的那样,“f”出现在每个字段中。但是,如果您更改这些字段然后提交表单,服务器会响应(在发布数据上使用 print_r())显示后端收到的 JSON 总是包含“f”作为每个字段的值,不是改变的值。
示例:使用用户名“test”等。
{"username":"f","password":"f","name":"f","email":"f"}
因此,当我输入表单时,$scope 中的值由于某种原因没有得到更新。是什么赋予了?