我正在使用表单在我的应用程序中创建用户。我也使用相同的表单来更新用户配置文件,并且我正在从数据库中加载值。如果用户没有更改编辑表单中的任何内容并提交表单,则范围没有用户数据。例如。
<select ng-model="user.gender">
<option ng-selected="userGender==male" value="male">male</optoin>
<option ng-selected="userGender==female" value="female">female</option>
</select>
提交功能:
$scope.updateUser = function() {
var userData = $scope.user;
var url = '/userModule';
$http.post(url, userData).
success(function(response) {
console.log(response);
});
};
如果用户不会触摸性别下拉列表,则在提交表单时,用户范围对象中将没有性别索引。
如何将所有 ng-pristine 或 ng-untouched 字段纳入范围。