admin管理员组文章数量:1322867
When I call put
or customPUT
and check the request body in the browser, the original object is sent, not the updated one. I checked the RestAngular object with a {{ object }}
and it is being updated.
Here is the controller (APIUsers
is a RestAngular Service):
$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;
});
};
Here is the Jade (HTML Template Code):
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
When I call put
or customPUT
and check the request body in the browser, the original object is sent, not the updated one. I checked the RestAngular object with a {{ object }}
and it is being updated.
Here is the controller (APIUsers
is a RestAngular Service):
$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;
});
};
Here is the Jade (HTML Template Code):
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
Share
Improve this question
edited Jun 28, 2014 at 1:28
sinθ
asked Jun 28, 2014 at 0:55
sinθsinθ
11.5k26 gold badges89 silver badges124 bronze badges
2
-
do you have,
RestangularProvider.setDefaultHttpFields({cache: true});
set somewhere ? – lucuma Commented Jun 28, 2014 at 1:45 - @sinθ Check the answer. Sadly it is a known bug. – Diosney Commented Mar 3, 2015 at 22:46
2 Answers
Reset to default 7It is an old and known Restangular bug, see it at https://github./mgonto/restangular/issues/713
To make this work in the meanwhile is fixed (it seems that are working to fix it), you can use the code below:
$scope.submit = function submit() {
Restangular
.copy($scope.ledger)
.save()
.then(function () {
growl.success(gettext('Updated successfully.'));
});
};
I had the same problem. I think you need to wait for the digest cycle to plete for the underlying restangular object to update.
Try wrapping your put()
behind a $timeout
call:
$timeout(function () {
$scope.objects.user.customPUT($scope.objects.user).then(function(resp) {
$scope.errors = [];
}, function(err) {
console.log(err.data);
$scope.errors = err.data.errors;
});
});
本文标签: javascriptRestAngular put and customPUT are sending old objectnot updated oneStack Overflow
版权声明:本文标题:javascript - RestAngular: put and customPUT are sending old object, not updated one - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742109518a2421178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论