我在Angular js中有一个Reactivemongo项目,我正在尝试从集合中删除文档。我写了我的Scala控制器:
def delete = Action.async {
collection.remove(BSONDocument("_id" -> _id)).map(_ => Ok(s"User Deleted")).recover { case _ => InternalServerError }}
我的Angular控制器如下:
controller("GuestCtrl", ["$scope", "$http", function($scope, $http){
$http.get("/guest/all").success(function(res){
console.log(res);
$scope.guests = res;
});
$scope.deleteGuest = function(guest){
console.log(guest);
$http.post("/guest/delete", guest).success(function(result){
});
};
$scope.registerGuest = function(newguest){
console.log(newguest);
$http.post("/guest/create", newguest).success(function(result){
$scope.newguest = result;
});
};
}]);
我的角度html页面是:
<div class= "col-md-5">
<ul class="guests">
<li ng-repeat="guest in guests ">
<h1>{{guest.name}}</h1>
<p>{{guest.address}}</p>
<input type="submit" value="Delete" ng-click="deleteGuest(guest)">
<input type="submit" value="Update" ng-click="updateGuest(guest)">
</li>
</ul>
</div>
如果有人知道如何进行更新和删除,请帮我解决!我在Angular控制器中写了一个删除函数,但它没有用。
答案 0 :(得分:0)
我实际上解决了这个问题......将我的角度控制器更新为
$scope.deleteGuest = function(guest){
console.log(guest);
$http.post("/guest/delete", {guest: guest}).success(function(result){
});
};
和我的Scala控制器
def delete = Action.async(parse.json){ request =>
val delGuest = ( request.body \ "guest").as[Guest]
println (delGuest)
guestCollection.remove(Json.obj("_id" -> delGuest._id)).map(_ => Ok).recover { case _ => InternalServerError }}
继续做一个帖子请求。