javascript - AngularJS and Restangular, trying to convert update method to API -


i'm trying convert basic crud operations api multiple components of application can use.

i have converted methods, except update 1 because calls each property on object declared before put request can executed.

controller

$scope.update = function(testimonial, id) {     var data = {         name: testimonial.name,         message: testimonial.message     };     dataservice.update(uri, data, $scope.id).then(function(response) {         console.log('successfully updated!');     },      function(error) {         console.log('error updating.');     }); } 

dataservice

dataservice.update = function(uri, data, id) {     var rest = restangular.one(uri, id);      angular.foreach(data, function(value, key) {         // needs in format below         // rest.key = data.key     });      // needs output this, depending on data passed     // rest.name = data.name;     // rest.message = data.message;      return rest.put(); } 

i tried describe problem in codes comments, reiterate cannot figure out how generate rest.name = data.name; without specifying name property because update function shouldn't need know object properties.

here update method looked before started trying make usable of components (this works)

testimonial.update = function(testimonial, id) {     var rest = restangular.one('testimonials', id);     rest.name = testimonial.name;     rest.message = testimonial.message;     return rest.put(); } 

how can recreate without specific properties parameters hard-coded in?

also, project has included lo-dash, if helps, don't know start problem. ton advice!

try like

angular.extend(rest,testimonial)  

https://docs.angularjs.org/api/ng/function/angular.extend


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -