Frage

In meiner App muss ich den Body-Parser verwenden, um Parameter anzufordern (Knoten.js AngularJS basierend auf angular-express-blog).Zum Beispiel (AngularJS-Controller):

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

Also laut AngularJS-Dokumenten $http.post('/someUrl', data).success(successCallback);

Aber ich weiß nicht, wie ich diese Daten im Knoten finden soll.in: js express.Ich kann nur bodyParser verwenden, der nur Daten in Form analysiert.

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

Wie kann ich also Daten übertragen und abrufen?

App.kokonfiguration:

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
  )

Und Datei anzeigen https://gist.github.com/3189377

War es hilfreich?

Lösung

Syntaxfehler $scope.comment sollte einfach sein comment:

$scope.changeComment = (comment) ->
  $http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, comment).success (data) ->
    $scope.post = data.post
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top