javascript - 从角度 5 POST 到节点 js
问题描述
角 5
onSubmit() {
const goData = {
fullName : this.RegisterForm.get('fullname').value,
email : this.RegisterForm.get('email').value,
userName : this.RegisterForm.get('username').value,
password : this.RegisterForm.get('password').value
}
console.log(JSON.stringify(goData))
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded',
})
};
this.http.post('http://localhost:7080/api/users/', goData , httpOptions)
.subscribe(data => {
console.log(data);
});
}
Express js 控制器
module.exports.usersAddOne = function(req, res){
console.log("Post new user");
User
.create({
fullName:req.body.fullName,
email:req.body.email,
userName:req.body.userName,
password:req.body.password
}, function(err, user){
if(err){
console.log("Error creating user"+err);
res
.status(404)
.json(err)
}else{
console.log("user created!", user);
res
.status(200)
.json(user);
}
});
}
我正在尝试以角度将一些数据发布到节点 js 中并且它成功发布但不发布任何被拒绝的数据
所以如果我发布 goData 那么它会发布空白
{
"_id": "5ae6f2f3912ee5b81d6df23a",
"__v": 0
},
但我希望它是像 fullName : "sam",, email : sam@gmail.com, userName : sam, password : ...
在节点控制台中它给了我未定义但我检查了它们定义的所有值并对数据进行硬编码但仍然没有结果
请帮忙,谢谢。
这是控制台输出
{"fullName":"sam","email":"sam","userName":"sam","password":"sam"}
register.component.ts:47 {__v: 0, _id: "5ae70e01ef0a592011724afa"}__v: 0_id: "5ae70e01ef0a592011724afa"__proto__: Object
XHR finished loading: POST "http://localhost:7080/api/users/".
解决方案
推荐阅读
- linux - Linux x86-64 syscall 何时会破坏 %r8、%r9 和 %r10?
- javascript - 显示 CSS 预加载器覆盖直到页面加载
- coq - 软件基础:weak_pumping 引理证明
- javascript - Cypress CSS Locator I am trying to locate a colour picker element from a parent class. I can get to the parent but not sure how to get the child
- javascript - posting form data with ajax javascript and php
- c++ - C ++循环中断'导致std :: find算法
- javascript - Next.js Puppeteer PDF 可下载链接返回错误
- android - 未为类型“Type”定义运算符“[]”。Flutter ListView 构建器
- icons - 图标行为怪异
- assembly - 如何在 6502 汇编器中正确使用中断处理程序?