我在AngularJS中有一个工厂,它是我的应用程序和我的后端之间的桥梁。当我尝试向工厂添加DELETE函数时,它会创建一个奇怪的URL,其中包含$ promise和$ resolved元素。
这是我的AngularJS代码。基本上:我不确定$ promise和$ resolve语句的来源(它们应该来自getById语句吗?)
这是错误:
DELETE http://localhost:8080/rest/speaker?$promise=%7B%7D&$resolved=false 415 (Unsupported Media Type)
1 /控制器
$scope.delete = function(id) {
var speaker = SpeakerService.getById(id);
SpeakerService.delete(speakerOrEmpty, function () {
$log.log('saved at: ' + new Date());
$route.reload();
});
};
2 /服务
this.getById = function (id, callback) {
return SpeakerResource.get({speakerId: id}, callback);
};
this.delete = function (data, callback) {
SpeakerResource.delete(data);
}
3 /工厂/资源
{
'delete': { method: 'DELETE' }
})
我所尝试的是将我的getById语句更新为此,但没有成功,因为我仍然在DELETE请求中看到$ resolved和$ promise项,尽管现在它们已设置为TRUE。
DELETE http://localhost:8080/rest/speaker?$promise=%7B%7D&$resolved=true&id=5419e8…5c1cde009%22,%22name%22:%22x%22%7D&organizationId=541a3eee772fb8f5c1cde009 415 (Unsupported Media Type)
$scope.delete = function(id) {
var speakerOrEmpty = SpeakerService.getById(id, function (data) {
speakerOrEmpty = data;
SpeakerService.delete(data, function () {
$log.log('saved at: ' + new Date());
$route.reload();
});
});
};
非常感谢您的帮助。非常感谢。