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?










share|improve this question


























    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?










    share|improve this question
























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 23:58









      frwebdev

      265




      265
























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





          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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

























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





          share|improve this answer





















          • 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















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





          share|improve this answer





















          • 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













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





          share|improve this answer












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






          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy