RestAngular Put request in AngularJs

306 views Asked by At

How can I make a put request in RestAngular?

This is what I tried.

 facUpdatePartner: function (partner)
        {
            var url = "UpdatePartner";
            var result = Restangular.one(url);
            return result.put(partner);
        }
1

There are 1 answers

0
manzapanza On

I don't know you full code but should is something like this:

facUpdatePartner: function (partner)
{
    return partner.put();
}

the partner need to come from a previous getOne or a get with Restangular. For example:

Controller:

vm.getCategories = function () {
  Category.get().then(function (categories) {
    vm.categories = categories;
  });
};

vm.getCategories();

vm.update = function(category){
  category.put().then(function(result){
    alert('UPDATED!');
  }).catch(function(err){
    alert('ERROR!');
  });
};

HTML:

...
<tr ng-repeat="category in vm.categories">
  <td>
    <input type="text" ng-model="category.name">
  </td>    
  <td>
    <button type="button" ng-click="vm.update(category)">
  </td>   
</tr>
....