Angular 资源参数未通过
Angular Resource parameters not passing
在 Angular 中使用资源服务制作 POST
时,它似乎没有随请求一起发送参数。在我添加第二个函数 (limit, offset) ->
(允许我为请求动态发送 header 值)
之前,该服务运行良好
添加新的评分功能
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
]
我已经解决了这个问题,方法是删除传递参数的空白函数,并向它自己的资源添加一个函数来设置参数。
limit = 15
offset = 0
res = $resource baseUrl + "person/:id/:role_id",
{ id: "@id", role_id:"@role_id", unit_id: event.id },
{ query: {
method: "GET",
isArray: true,
headers:
'X-Response-Limit': () ->
return limit
'X-Response-Offset': () ->
return offset
}
}
res.setLimit = (_limit, _offset)->
limit = _limit
offset = _offset
res
在 Angular 中使用资源服务制作 POST
时,它似乎没有随请求一起发送参数。在我添加第二个函数 (limit, offset) ->
(允许我为请求动态发送 header 值)
添加新的评分功能
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
]
我已经解决了这个问题,方法是删除传递参数的空白函数,并向它自己的资源添加一个函数来设置参数。
limit = 15
offset = 0
res = $resource baseUrl + "person/:id/:role_id",
{ id: "@id", role_id:"@role_id", unit_id: event.id },
{ query: {
method: "GET",
isArray: true,
headers:
'X-Response-Limit': () ->
return limit
'X-Response-Offset': () ->
return offset
}
}
res.setLimit = (_limit, _offset)->
limit = _limit
offset = _offset
res