我有一个包含结果集的表,每行都有编辑选项。点击“编辑”链接后,我可以在字段中填充内容。
但是如何使用REST服务编辑现有内容。
<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>
$scope.saveContact = function(){
//save or edit contact
};
我是用plunker创建的。 content EDIT using REST API
答案 0 :(得分:1)
我把它付诸实践。你接近解决方案。
这是工作plunker
我做了什么:
<强> HTML 强>
//I give the complete object instead of the id
ng-click="edit(result)"
<强>控制器强>
//I prefer to pass the entire object
$scope.edit = function(result){
$scope.cineresultsFrm = angular.copy(result);
};
服务
我刚刚删除了该服务。它不再有用了。
<强>控制器强>
$scope.saveContact = function(){
//The function given to $update() is the .then() function
$scope.cineresultsFrm.$update(function(){
//If the update succeed i update the whole list. Could be done a better way but if you don't have any performance issues that will do the job.
$scope.getMovies();
});
};
我也改变了你在诺言中处理“那么”的方式。但这只是一个品味问题。
$scope.getMovies = function(){
$scope.movieResults = movie.query(function() {
$scope.results = $scope.movieResults;
});
};
$scope.getMovies();
希望它能帮到你