angularjs - angular edit details using REST($resource) Service -


i have table result set , there edit option existing in each row. after clicking on 'edit' link, able populating content on fields.

but how edit existing content using rest service.

<table class="table-bordered table">             <thead>               <tr>                 <th>id</th>                 <th>director</th>                 <th>genre</th>                 <th>releaseyear</th>                 <th>title</th>                 <th>action</th>               </tr>             </thead>             <tbody>               <tr ng-repeat="result in results | orderby:'_id'">                 <td>{{result._id}}</td>                 <td>{{result.director}}</td>                 <td>{{result.genre}}</td>                 <td>{{result.releaseyear}}</td>                 <td>{{result.title}}</td>                 <td><a href="javascript:void(0)" ng-click="edit(result._id)">edit | </a><a href="javascript:void(0)" ng-click="delete()">delete</a></td>               </tr>             </tbody>           </table> 

controller

 $scope.savecontact = function(){     //save or edit contact   }; 

i have created in plunker. content edit using rest api

image

i put work. close solution.

here working plunker

what did :

1 - changed way of getting element form.

html

  //i give complete object instead of id   ng-click="edit(result)" 

controller

  //i prefer pass entire object   $scope.edit = function(result){     $scope.cineresultsfrm = angular.copy(result);   }; 

service

i removed service. wasn't useful anymore.

2 - used method of ressource on object

controller

$scope.savecontact = function(){     //the function given $update() .then() function     $scope.cineresultsfrm.$update(function(){       //if update succeed update whole list. done better way if don't have performance issues job.       $scope.getmovies();     });   }; 

i changed way handle "then" in promise. matter of taste.

  $scope.getmovies = function(){     $scope.movieresults = movie.query(function() {       $scope.results = $scope.movieresults;     });   };    $scope.getmovies(); 

hope helped you


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -