Richiedi dati in Node.js da AngularJs senza bodyparser
Domanda
Nella mia app ho bisogno di utilizzare il parser del corpo per richiedere params (node.js angolarjs basato su Angular-express-blog ).Ad esempio (Controller AngularJS):
$scope.changeComment = (comment) ->
$http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, $scope.comment).success (data) ->
$scope.post = data.post
.
Quindi secondo AngularJS Docs $http.post('/someUrl', data).success(successCallback);
Ma non so come ho trovato questi dati in node.js Express.Posso usare solo Bodyparser, che analizza solo i dati nella forma.
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) ->
.
Allora, come posso trasmettere e afferrare i dati?
App.Cofigurazione:
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
)
.
e visualizza file https://gist.github.com/3189377
Soluzione
Errore di sintassi $scope.comment
deve essere solo comment
:
$scope.changeComment = (comment) ->
$http.put('/api/post/' + $routeParams.id + '/editComment/' + comment._id, comment).success (data) ->
$scope.post = data.post
. Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow