angularjs - How to set an object to the updated value returned by Angular $resource? -


how save object $resource , set object api response value returned $resource?

i have object, value (which part of array of objects iterating through), save rest api.

when save successful, api responds same object, plus details such object's id (if save create) or perhaps file paths end saved to. stuff front end can't know until end adds it.

i want update saved value object details returned in response, can't figure out how it.

i have tried returning response $resource callbacks, can't make work. returns $$state object (which don't know with) rather response. may doing wrong.

in case rather set value object response object inside success callback, because want set object response when save successful, not when there's error.

but don't know how pass value object callback updated, crux of problem.

(and can't figure out how search array object inside callback because $resource success response doesn't include $$hashkey. error response includes $$hashkey. approach seems kludge me anyway)

here basic pattern trying use. i'm hoping point out flaw pattern, or show me how pass value callbacks, or whatever. ideally i'd know best practice pattern saving objects $resource , updating them response data.

(resource name have given in example angular factory returns $resource object.)

  function success(response) {     //i want set value response here, value out of scope     //so instead returns $$state rather response     return response;   }   function error(response) {     status.reporterror(response);   }    value = resource.create(value)    .$promise.then(success, error); 

i imagine find value somewhere in $scope of callback (?) i'm trying avoid using $scope due pending deprecation.

thanks in advance

jay dee

should this:

resource.create(value, function(success) {    value.id = success.id;//depends on return, may success.data.id or similar }, function(error) {}); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -