angularjs http.patch partial model
up vote
1
down vote
favorite
I'm probably groping in a glass of water...
I have a data source like this in my controller
$scope.data = { name: John, lastname: Doh, age: 31 }
In my view i have a form to edit only name
<input type=text ng-model="data.name">
Now, on click i would like to send only the name to a specific service, but if I do http.patch('myapi/path',data)
i send all the model data, also lastname and age...
Ho can i fix to send only name?
angularjs
add a comment |
up vote
1
down vote
favorite
I'm probably groping in a glass of water...
I have a data source like this in my controller
$scope.data = { name: John, lastname: Doh, age: 31 }
In my view i have a form to edit only name
<input type=text ng-model="data.name">
Now, on click i would like to send only the name to a specific service, but if I do http.patch('myapi/path',data)
i send all the model data, also lastname and age...
Ho can i fix to send only name?
angularjs
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm probably groping in a glass of water...
I have a data source like this in my controller
$scope.data = { name: John, lastname: Doh, age: 31 }
In my view i have a form to edit only name
<input type=text ng-model="data.name">
Now, on click i would like to send only the name to a specific service, but if I do http.patch('myapi/path',data)
i send all the model data, also lastname and age...
Ho can i fix to send only name?
angularjs
I'm probably groping in a glass of water...
I have a data source like this in my controller
$scope.data = { name: John, lastname: Doh, age: 31 }
In my view i have a form to edit only name
<input type=text ng-model="data.name">
Now, on click i would like to send only the name to a specific service, but if I do http.patch('myapi/path',data)
i send all the model data, also lastname and age...
Ho can i fix to send only name?
angularjs
angularjs
asked Nov 18 at 23:58
frwebdev
265
265
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You have defined $scope.data
to be an object with 3 keys name
, lastnam
and age
. Then, you are using the same object to perform a http patch. If you only wish to send the new name, you can try this
http.patch('myapi/path',{name: data.name})
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You have defined $scope.data
to be an object with 3 keys name
, lastnam
and age
. Then, you are using the same object to perform a http patch. If you only wish to send the new name, you can try this
http.patch('myapi/path',{name: data.name})
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
add a comment |
up vote
1
down vote
accepted
You have defined $scope.data
to be an object with 3 keys name
, lastnam
and age
. Then, you are using the same object to perform a http patch. If you only wish to send the new name, you can try this
http.patch('myapi/path',{name: data.name})
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You have defined $scope.data
to be an object with 3 keys name
, lastnam
and age
. Then, you are using the same object to perform a http patch. If you only wish to send the new name, you can try this
http.patch('myapi/path',{name: data.name})
You have defined $scope.data
to be an object with 3 keys name
, lastnam
and age
. Then, you are using the same object to perform a http patch. If you only wish to send the new name, you can try this
http.patch('myapi/path',{name: data.name})
answered Nov 19 at 0:22
Bishal
554216
554216
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
add a comment |
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
Sure it works. I wondered if there was a method that does not provide to rewrite all the values manually. (my real form is about 20 fields)
– frwebdev
Nov 19 at 9:16
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
HTTP PATCH is to make changes to existing resource. So, you should filter the object properties before sending the patch request. With a number of properties, this can be less manageable, maybe you could have a function that does a diff to calculate what has changed and returns an object with only the diff properties
– Bishal
Nov 20 at 0:20
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366688%2fangularjs-http-patch-partial-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown