BodyParserなしでAngularJSからNode.jsのデータを要求する
質問
私のアプリでは、Body Parserを使用してparamsを要求する必要があります(angular-express-blog )たとえば(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 Expressでこのデータを見つける方法がわかりません。私は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
)
.
とファイルの表示 https://gist.github.com/3189377
解決
構文エラー$scope.comment
はcomment
だけである必要があります。
$scope.changeComment = (comment) ->
$http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, comment).success (data) ->
$scope.post = data.post
. 所属していません StackOverflow