Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从angular 5发布到节点js_Javascript_Node.js_Angular - Fatal编程技术网

Javascript 从angular 5发布到节点js

Javascript 从angular 5发布到节点js,javascript,node.js,angular,Javascript,Node.js,Angular,角度5 onSubmit() { const goData = { fullName : this.RegisterForm.get('fullname').value, email : this.RegisterForm.get('email').value, userName : this.RegisterForm.get('username').value, password : this.Registe

角度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);
    }
  });
}
我试图在angular中将一些数据发布到node js中,它成功地发布了一些数据,但没有发布任何未定义的数据

所以如果我发布goData,那么它会发布空白

{
"_id": "5ae6f2f3912ee5b81d6df23a",
"__v": 0
},
但我希望它像数据一样 全名:“山姆”,, 电邮:sam@gmail.com, 用户名:sam, 密码:

在节点控制台中,它给出了未定义的值,但我检查了所有已定义的值,并对数据进行了硬编码,但仍然没有结果

请帮忙,谢谢

这是控制台输出

{"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/".

您正在使用bodyparser吗?在网络选项卡中可以看到什么?实际的请求负载是否包含数据?我认为数据中存在问题,以JSON.stringify(goData)@Curt{“fullName”:“sam”,“email”:“sam”,“userName”:“sam”,“password”:“sam”}:这就是负载@Curt