-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to update existing Resource #64
Comments
Resources are not mutable by design. Your code should look like this: $http({url: '/message/23'})
.then((message) => {
return message.$request().$post('self', {}, {
text: 'New Text',
});
})
.then(() => {
console.log('Saved');
})
.catch((error) => {
console.error(error);
}); |
If you want to execute HTTP calls, you always have to use You can find the methods here: |
By the way: Which version of angular-hal are you using? My answer only applies to the latest major release ( |
By the way: the Pull Request #63 will add a shorter syntax for HTTP calls on the resource itself. As soon as it is merged, the example code will look like this: $http({url: '/message/23'})
.then((message) => {
return message.$request().$postSelf({
text: 'New Text',
});
})
.then(() => {
console.log('Saved');
})
.catch((error) => {
console.error(error);
}); |
I will update to major soon. In my client angular application, I maintain some resources list, and when i need to change one resource I can use at this point the $postSelf , or $post('self' ... ) But after a change like the described above, do you suggest to make an immediately $get, to obtain a new resource changed and replace the old immutable one? As client, receiving 200, 201 I exepect the resource is changed as i requested. |
Yes.
If you need a mutable object, just copy it... |
This is a question, for a clarification.
I get a Resource from server, and I would like to update it.
Looking the source code if I understood well the Resources are created with not configurable fields.
How should I do to change a Resource attribute and send it back to the server, as updated?
E.g.:
$http({url: '/message/23'}).then(function(message){
message.text = 'new Text'; //I cant't ! <<<<<<<<
message.$post();
});
I would like to above to try to clone the resource, or make a copy with configurable attribute...
I can't understand if I should use $response() or any other method.
Thanks
Francesco
The text was updated successfully, but these errors were encountered: