試試這個:
的index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-resource.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<div ng-controller="AuthorizeController">
<form name="authorizeForm" novalidate>
<label>Login</label>
<input type="text" name="login" ng-model="authorizeClaim.login">
<br/>
<label>Code</label>
<input type="text" name="code" ng-model="authorizeClaim.code">
<br/>
<button ng-click="doAuthorizeClaim()">Authorize claim</button>
</form>
</div>
</body>
</html>
的script.js
var myApp = angular.module('myApp', ['ngResource', 'myAppServices']);
myApp.controller('AuthorizeController', ['$scope', 'Authorize',
function($scope, Authorize) {
$scope.doAuthorizeClaim = function() {
Authorize.save($scope.authorizeClaim, function() {
alert('Authorize claim saved');
});
};
}
]);
var myAppServices = angular.module('myAppServices', ['ngResource']);
myAppServices.factory('Authorize', ['$resource',
function($resource) {
return $resource('/api/authClaims', {}, {});
}
]);
Plunker example
如果運行這個例子,你可以在網絡看到(德veloper工具/ Firebug)這樣的事情:
Request URL: http://run.plnkr.co/api/authClaims
Request Method: POST
Status Code: 404 Not Found
Request Payloadview source
{login:test1, code:code1}
所以方法POST的作品。