【发布时间】:2016-05-13 07:47:42
【问题描述】:
在 Angular 中使用资源服务创建 POST 时,它似乎没有将参数与请求一起发送。在我添加第二个函数(limit, offset) -> (它允许我为请求动态发送标头值)之前,该服务运行良好
新增评分功能
newScore = new Score()
newScore.leadership = $scope.scoreLeadership
newScore.planning = $scope.scorePlanning
newScore.attitude = $scope.scoreAttitude
newScore.accomplishment = $scope.scoreAccomplishment
newScore.total = $scope.scoreTotal
newScore.comment = $scope.scoreComment
newScore.location_id = $scope.scoreBase.id
newScore.event_id = event.id
newScore.unit_id = $scope.scoreTeam.id
newScore.save null, (data) ->
data.unit = $scope.teams[$scope.teams.indexOf($scope.scoreTeam)]
data.location = $scope.bases[$scope.bases.indexOf($scope.scoreBase)]
showSuccess()
$scope.addScore.$setPristine()
$scope.scoreLeadership = undefined
$scope.scorePlanning = undefined
$scope.scoreAttitude = undefined
$scope.scoreAccomplishment = undefined
$scope.scoreTotal = undefined
$scope.scoreComment = undefined
$scope.scoreBase = undefined
$scope.scoreTeam = undefined
$scope.scores.push(data)
评分服务
define [
"service/services"
], (services) ->
main = ($resource, event, baseUrl) ->
(limit, offset)->
$resource baseUrl + "score/:id", {
id: "@id"
event_id: event.id
},
{ query: {
method: "GET",
headers: {'X-Response-Limit' : limit , 'X-Response-Offset' : offset},
isArray: true
},
save: {
method: "POST",
isArray: false
}
}
services.factory "Score", [
"$resource"
"event"
"baseUrl"
main
]
【问题讨论】:
标签: angularjs angularjs-directive coffeescript angularjs-scope angularjs-resource