Every time I use the put
or customPUT
method and inspect the request body in the browser, it always sends the original object instead of the updated one. Interestingly, when I check the RestAngular object with a {{ object }}
, it clearly shows that it is being updated.
Take a look at the following controller (where APIUsers
represents 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;
});
};
And 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