Question

In my app I need to use body parser to request params (Node.js AngularJS based on angular-express-blog). For example (AngularJS controller):

$scope.changeComment = (comment) ->
  $http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, $scope.comment).success (data) ->
    $scope.post = data.post

So according to AngularJS docs $http.post('/someUrl', data).success(successCallback);

But I dont know how to found this data in node.js express. I can only use bodyParser, that parse only data in form.

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) ->

So how can I transmit and grab data?

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
  )

And view file https://gist.github.com/3189377

Was it helpful?

Solution

Syntax error $scope.comment should be just comment:

$scope.changeComment = (comment) ->
  $http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, comment).success (data) ->
    $scope.post = data.post
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top