sin*_*inθ 4 javascript rest angularjs restangular
当我在浏览器中调用put或customPUT检查请求主体时,将发送原始对象,而不是更新的对象.我检查了该RestAngular对象{{ object }},它是被更新.
这是控制器(APIUsers是一个RestAngular服务):
$scope.objects = {};
(function waitForNgInit(fnct) {
$scope.$watch('userID', function(newVal) {
if (newVal !== undefined) {
fnct();
}
});
})(function retrieveUser() {
$scope.objects.user = APIUsers.one($scope.userID).get().$object;
});
$scope.saveSettings = function() {
$scope.objects.user.customPUT($scope.objects.user).then(function(resp) {
$scope.errors = [];
}, function(err) {
console.log(err.data);
$scope.errors = err.data.errors;
});
};
Run Code Online (Sandbox Code Playgroud)
这是Jade(HTML模板代码):
div.user-settings.form-section(ng-controller="userSettingsFormController")
{{ objects }}
ul.error-box(ng-show="errors != undefined && errors.legnth != 0")
li(ng-repeat="error in errors") {{ error.msg }}
.form-group
label(for="username") Username
input(type="textfield" ng-model="objects.user.username")
.form-group
label(for="username") Email
input(type="textfield" ng-model="objects.user.email")
.form-group
label(for="username") Profile Picture
input(type="file" ng-model="objects.user.profilePicture")
span.submit-button(ng-click="saveSettings()") Save Changes
Run Code Online (Sandbox Code Playgroud)
这是一个古老且已知的Restangular bug,请访问https://github.com/mgonto/restangular/issues/713
为了使这项工作在同时是固定的(似乎正在努力修复它),你可以使用下面的代码:
$scope.submit = function submit() {
Restangular
.copy($scope.ledger)
.save()
.then(function () {
growl.success(gettext('Updated successfully.'));
});
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4172 次 |
| 最近记录: |