例如
controller.js
function RegisterCtrl($scope, $http, $location) {
$scope.form = {};
$scope.submitPost = function() {
$http.post('/register', $scope.form).
success(function(data) {
$location.path('/');
});
};
}
路由/ index.js
app.post('/register', sessionHandler.handleSignup);
路由/ session.js
this.handleSignup = function(req, res, next) {
"use strict";
// when i try to access into the controller by using "data" it said my "data"
// is not declare, what should i pass into `var data` = ?? in order to
// access the data from controller
var email = data.email,
confirmEmail = data.confirmEmail,
password = data.password,
confirmPassword = data.confirmPassword,
firstName = data.firstName,
lastName = data.lastName,
penName = data.penName,
publicUsername = data.publicUsername;
}
答案 0 :(得分:1)
您必须使用express.urlencoded()
和express.json()
middleware来解析通过HTTP
DELETE
/ POST
发送的正文数据/ PUT
。
之后,body
对象上会有一个req
属性,您可以像这样使用它:
this.handleSignup = function(req, res, next) {
"use strict";
var data = req.body,
email = data.confirmEmail,
// etc.
};
答案 1 :(得分:0)
从您的http帖子中的成功响应中,您可以为其分配范围,然后将其显示给您的部分。这样的事情。
$http.post('/register', $scope.form).
success(function(data) {
$scope.data = data;
});
然后从你的部分/视图
<div>{{data}}</div>
此致