我正在尝试通过它的id删除数据,但它无法正常工作。 当我设置我想要删除的数据的ID时,它可以工作。我需要你的帮助。
我的HTML代码:
<div data-ng-controller="deletePinCtrl">
<button data-ng-click="deletePin()">delete</button>
</div>
<h3>{{pin.title}}</h3>
<h4>{{pin.content}}</h4>
My Angular code:
.controller("deletePinCtrl", function($scope, $http){
$scope.deletePin = function() {
var obj = { "id": "value"};
var config = { data: JSON.stringify(obj) };
$http.delete('http://localhost:8080/SpringMVCHibernate/rest/delete', config).
then(function(response) {
alert("pin is deleted");
}, function(response) {
alert("try again");
});
}
})
答案 0 :(得分:0)
在函数中传递id
<button data-ng-click="deletePin(pin.id)">delete</button>
并在此处设置
$scope.deletePin = function(value) {
var obj = { "id": value}; // now id have its id