Question

I have started using Restangular and it seems to be a very good library. However I have the following query. In order to update an object I am using the below code

Restangular.one("accounts", $scope.accountEdit.id).get().then(function(account) {
    account = Restangular.copy($scope.accountEdit);
    account.put();
});

In the above code I have to do a get request to the server and then update it. Is there a better way to just avoid the server call as I would like to update the object from my scope to the server.

Was it helpful?

Solution

you can use customPUT like this,

Restangular.one("accounts").customPUT($scope.accountEdit, $scope.accountEdit.id).then(function(account) {
     TO-DO
});

customPUT([elem, path, params, headers]): Does a PUT to the specific path. Optionally you can set params and headers and elem. Elem is the element to post. If it's not set, it's assumed that it's the element itself from which you're calling this function.

besides this you can extend your object with Restangular which gives you same result as your callback function did...

angular.extend($scope.accountEdit, Restangular.one("accounts", $scope.accountEdit.id));
$scope.accountEdit.put();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top