作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的用户控制面板上的更改密码功能不起作用。它从输入中获取值并将它们从 Controller 传递到服务,服务接收它们,但是当他尝试使用它们到达后端时,调试控制台返回:无法读取未定义的属性“协议(protocol)”。
重要:请引用我的预览问题here在编写解决方案之前,请先了解为什么我必须使用对象的字段来确定输入范围。请考虑将整个对象发送到后端不是一个选项,谢谢。
表单 (.html):
<accordion-group heading="Change password" is-open="changePasswordStatus.open" style="cursor: pointer">
<div>
<div>
<form class="form-horizontal" role="form">
<form-row model="password.newPassword" name="New: " size="col-sm-8"></form-row>
<form-row model="password.repeatedNewPassword" name="Repeat: " size="col-sm-8"></form-row>
<form-row model="password.currentPassword" name="Current: " size="col-sm-8"></form-row>
<br>
</form>
</div>
<div>
<button class="btn btn-default btn-sm" data-ng-click="changePassword()">Save</button>
<button class="btn btn-warning btn-sm" ng-click="changePasswordStatus.open = !changePasswordStatus.open">Cancel</button>
</div>
</div>
</accordion-group>
userController.js:
collectionsApp.controller('userController', function($scope, userService, $timeout, $state) {
$scope.password = {
newPassword : "",
repeatedNewPassword : "",
currentPassword : ""
}
$scope.init = function() {
userService.getCurrentUser(getCurrentUser);
}
$scope.changePassword = function() {
if ($scope.password.newPassword === $scope.password.repeatedNewPassword) {
userService.changePassword($scope.password.newPassword, $scope.password.currentPassword);
}
}
...
userService.js:
collectionsApp.service('userService', function($http) {
return {
changePassword : function(newPassword, currentPassword) {
$http.post('/user/changePassword', newPassword, currentPassword);
}
};
});
调试:
控制台错误:
最佳答案
根据$http reference ,post 方法参数是
所以,试试这个:
collectionsApp.service('userService', function($http) {
return {
changePassword : function(newPassword, currentPassword) {
var data = {
newPassword: newPassword,
currentPassword: currentPassword
};
$http.post('/user/changePassword', data);
}
};
});
关于javascript - userServic不会将数据传递到后端: Cannot read property 'protocol' of undefined - AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25548611/
我是一名优秀的程序员,十分优秀!