문제

내 앱에서 Body Parser를 사용하여 params를 요청해야합니다 ( "nofollow noreferrer">앵글 익스프레스 블로그 ).예 : (ANGURUJS 컨트롤러) :

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

Angularjs 문서에 따르면 $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
  )
.

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

도움이 되었습니까?

해결책

구문 오류 $scope.commentcomment :

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top