我在PasswordSrvc中有当前代码:
doResetPassword: function (passwordCommand) {
var response = {data : {errors: ""}};
if (passwordCommand.password !== passwordCommand.passwordConfirm) {
response.data.errors = response.data.errors.concat("Passwords do not match!\n");
}
if (passwordCommand.password.length < 6 || passwordCommand.passwordConfirm.length < 6) {
response.data.errors = response.data.errors.concat("Password too short!\n")
}
if (response.data.errors !== "") {
return response;
}
else {
passwordCommand.token = $location.search().token;
return $http.put(apiUrl + 'password/doResetPassword', passwordCommand);
}
}
来自:
PasswordSrvc.doResetPassword($scope.passwordCommand).then(function (response){
console.log(JSON.stringify(response));
if (response.data.errors) {
$scope.errorMessage = response.data.errors;
} else {
$location.path('/authority/passwordChanged');
}
});
问题是,如果发生验证错误并且我最终从以下地址返回,我总是将响应视为“未定义”:
if (response.data.errors !== "") {
return response;
}
为什么会这样?怎么修好? 我的意思是,从
返回时 else {
passwordCommand.token = $location.search().token;
return $http.put(apiUrl + 'password/doResetPassword', passwordCommand);
}
它工作正常,我得到了我想要的任何东西,但为什么它不能用于“手动创建的响应”?
由于