我正在使用一个API,使用djang-tastypie作为后端,AngularJ用于前端.我使用
angularjs $http发送CRUD的请求. GET,POST,PUT一切都很好,但是当我尝试发送一个PATCH请求时,有错误方法PATCH没有被定义.我已经创建了一个api电话工厂,但PATCH请求不在那里工作.
原文链接:https://www.f2er.com/angularjs/140797.htmlangular.module('tastypieModule',['ngResource']). factory('apiCall',function($http,$resource) { delete $http.defaults.headers.common['X-Requested-With']; var apiCall = $resource('/api/v1/:type/:id/',{type: '@type',username: '@userName',api_key: '@api_key',user: '@userID',id: '@id'},{ get: {method: 'GET'},post: {method: 'POST',headers: {'Content-Type': 'application/json'}},del: {method: 'DELETE',update: {method: 'PUT',pupdate:{method:'PATCH',headers: {'Content-Type': 'application/json'}} } ); return apiCall; }); function MyCtrl($scope,$resource){ $scope.edit=function(){ id=$scope.E_id $http.pupdate('/api/v1/quizsetting/'+id+'/',editedquizsetting). success(function(data,status) { $scope.status = status; $scope.data = data; $scope.editQuizSettingModal = false; //$scope.quizsettinglist.objects[$scope.e_quizsettingindex]=data; $(".message").append("object has been created successfully"); }) . error(function(data,status) { $scope.data = data || "Request Failed"; $scope.status = status; }); }; }
这是我的HTML代码
<div ng-app="myApp"> <div ng-controller="MyCtrl"> <button type="button" ng-click="edit()">Edit</button> </div></div>
当我发送路径请求使用这个代码在控制台它显示http.patch不是一个功能.
告诉我如何配置ng-app和服务以使用angularjs发送PATCH请求.