如何在 angularjs 中创建 $http 删除请求
How to create $http delete req in angularjs
我只想通过单击按钮删除 table 的一行。我是这样的
.controller('removeInput' , function($scope, $http) {
$scope.remove = function(index){
var inputId = {'inputId': $scope.inputId};
$http.delete(baseUrl + '/input/' ,inputId, _auth)
.success(function (){
console.log('deleted');
}).error(function(err){
console.log(err);
});
};
});
在html中是这样的
<tbody ng-controller = "input">
<tr ng-repeat = "inputs in inputData">
<td ng-model = "inputId">{{inputs.inputId}}</td>
<td><img ng-src = "{{inputs.thumbnailUrl}}"/></td>
<td>{{inputs.filename}}</td>
<td></td>
<td>{{inputs.updatedAt.date}}</td>
<td ng-controller = "removeInput">
<a class = "btn btn-option" ng-click = "remove(index)">
<span class = "glyphicon glyphicon-remove"></span>
</a>
</td>
</tr>
</tbody>
它不起作用。请指出我错在哪里?
您并没有真正传递正确的值。不清楚 $scope.inputId
是什么,但它不是您要删除的项目的值。试试这个:
<a class = "btn btn-option" ng-click = "remove(inputs.inputId)">
并在 JavaScript 中:
$scope.remove = function(index){
$http.delete(baseUrl + '/input/' + index, _auth)
....
我只想通过单击按钮删除 table 的一行。我是这样的
.controller('removeInput' , function($scope, $http) {
$scope.remove = function(index){
var inputId = {'inputId': $scope.inputId};
$http.delete(baseUrl + '/input/' ,inputId, _auth)
.success(function (){
console.log('deleted');
}).error(function(err){
console.log(err);
});
};
});
在html中是这样的
<tbody ng-controller = "input">
<tr ng-repeat = "inputs in inputData">
<td ng-model = "inputId">{{inputs.inputId}}</td>
<td><img ng-src = "{{inputs.thumbnailUrl}}"/></td>
<td>{{inputs.filename}}</td>
<td></td>
<td>{{inputs.updatedAt.date}}</td>
<td ng-controller = "removeInput">
<a class = "btn btn-option" ng-click = "remove(index)">
<span class = "glyphicon glyphicon-remove"></span>
</a>
</td>
</tr>
</tbody>
它不起作用。请指出我错在哪里?
您并没有真正传递正确的值。不清楚 $scope.inputId
是什么,但它不是您要删除的项目的值。试试这个:
<a class = "btn btn-option" ng-click = "remove(inputs.inputId)">
并在 JavaScript 中:
$scope.remove = function(index){
$http.delete(baseUrl + '/input/' + index, _auth)
....