前端代码
<button data-ng-click="deleteRec()" id="Delete">delete</button>
var app = angular.module('myApp', ['ngResource']);
app.controller('UserController', ['$scope', '$resource',function($scope,$resource)
{
$scope.deleteRec = function()
{
User = $resource(
'delete/:username',
{method:'DELETE', params: {username: '@username'}});
User.delete({username: $scope.myform.username}).then(function successCallback(response)
{
$scope.Message = response;
}, function errorCallback(response) {
});
$scope.myform.username = "";
$scope.myform.phone="";
$scope.myform.email="";
$scope.myform.address="";
$scope.myform.password="";
};
}]);
控制器代码
@RequestMapping(value="/delete/{username}")
public @ResponseBody String delete(@PathVariable("username") String username)
{
String user=retrievedataservice.delete(username);
return null;
}
错误是这样的 TypeError: User.delete(...).then is not a function 实际上,User 是一个对象和 delete() 方法,用于在 Spring Controller 方法 delete() 中传递参数。