在我的应用程序中,我需要使用body解析器来请求params(基于angular-express-blog的Node.js AngularJS)。例如(AngularJS控制器):
$scope.changeComment = (comment) ->
$http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, $scope.comment).success (data) ->
$scope.post = data.post
所以根据AngularJS docs $http.post('/someUrl', data).success(successCallback);
但我不知道如何在node.js表达中找到这些数据。我只能使用bodyParser,它只解析表单中的数据。
app.put '/api/post/:id/editComment/:cid' = (req, res) ->
id = req.params.id;
cid = req.params.cid;
console.log req
Post.findById id, (err, post) ->
unless err
comment = post.comments.id(cid)
console.log req.body
comment.text = req.body.text
post.save (err1) ->
那么如何传输和获取数据?
app.cofiguration:
app.configure "development", ->
app.use express.bodyParser()
app.use express.methodOverride()
app.use express.static(__dirname + '/public')
app.use express.errorHandler(
dumpExceptions: true
showStack: true
)
答案 0 :(得分:1)
语法错误$scope.comment
应该只是comment
:
$scope.changeComment = (comment) ->
$http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, comment).success (data) ->
$scope.post = data.post