1

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?

1 Answer 1

1

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})
Sign up to request clarification or add additional context in comments.

2 Comments

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)
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.