当前位置: 首页>NodeJS>ExpressJS>ExpressJS AngularJS POST

ExpressJS AngularJS POST

时间:2015-06-30 00:48 来源:网络整理 作者:KKWL 点击:
The body-parser module for Node.js (Express) can get every data from your form post into a single object called req.body, so if you have a $scope object to define your form data you can inject directly that to have the same properties copie

The body-parser module for Node.js (Express) can get every data from your form post into a single object called req.body, so if you have a $scope object to define your form data you can inject directly that to have the same properties copied on req.body:

HTML:

<form> <input type="text" ng-model="formData.desc" placeholder="Enter desc" /> <input type="text" ng-model="formData.title" placeholder="Enter title" /> <button ng-click="sub(desc)">Submit</button> </form>

Now when you submit it via $http.post('/view1', $scope.formData)you will get the same object, for example:

app.post('/view1', function(req, res) { console.log(req.body.desc); res.end(); });

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------