Node.js 加载资源失败:net::ERR_CONNECTION_RESET和后端端错误:非法参数:未定义,字符串

Node.js 加载资源失败:net::ERR_CONNECTION_RESET和后端端错误:非法参数:未定义,字符串,node.js,angular,typescript,Node.js,Angular,Typescript,我正在开发一个简单的注册和登录应用程序 我试图通过表单保存帖子,在控制台中提交表单后出现此错误:angualr的HttpErrorResponse以及后端控制台if(err)throw err; ^ 错误:非法参数:未定义,字符串 我遵循angular 2教程,但我使用angular 6 这是教程链接https://www.youtube.com/watch?v=dFftMN32jyQ&list=PLillGF-RfqbZMNtaOXJQiDebNXjVapWPZ&index=7 auth.Se

我正在开发一个简单的注册和登录应用程序 我试图通过表单保存帖子,在控制台中提交表单后出现此错误:angualr的HttpErrorResponse以及后端控制台if(err)throw err; ^ 错误:非法参数:未定义,字符串

我遵循angular 2教程,但我使用angular 6 这是教程链接
https://www.youtube.com/watch?v=dFftMN32jyQ&list=PLillGF-RfqbZMNtaOXJQiDebNXjVapWPZ&index=7

auth.Service.ts register.component.ts register.component.html
寄存器
名称
用户名
电子邮件
密码

非常感谢您的帮助。

您似乎在发布传入变量中的字符串“user”,而不是object user

这:

应该是这样的:

return this.http.post('http://localhost:3000/users/register', user, {headers: headers})
import { Component, OnInit } from '@angular/core';
import { ValidateService } from '../../services/validate.service';
import { AuthService  } from '../../services/auth.service';
import { FlashMessagesService } from 'angular2-flash-messages/module/flash-messages.service';
import { Router } from '@angular/router';


@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {

  name: String;
  username: String;
  email: String;
  password: String;


  constructor(private validateService: ValidateService, private flashMessage: FlashMessagesService,
    private authService: AuthService, private router: Router) { }

  ngOnInit() {
  }

  onRegisterSubmit(){
    const user = {
      name: this.name,
      email: this.email,
      username: this.username,
      password: this.password
    }

    //Required Field
    if(!this.validateService.validateRegister(user)){
      //console.log('Please Fill in all feilds');
      this.flashMessage.show('Please Fill in all feilds',{cssClass:'alert-danger', timeout: 3000});
     return false;
    }
     //Required Email
     if(!this.validateService.validateEmail(user.email)){
     // console.log('Please use a valid email');
       this.flashMessage.show('Please use a valid email',{cssClass:'alert-danger', timeout: 3000});
      return false;
    }
     //Register User
     this.authService.registerUser(user).subscribe(data =>{
         if(data){
          this.flashMessage.show('You are now registered and can log in',{cssClass:'alert-success', timeout: 3000});
          this.router.navigate(['/login']) ;
        }else{
          this.flashMessage.show('Something went wrong',{cssClass:'alert-danger', timeout: 3000});
          this.router.navigate(['/register']) ;
         }
     }); 

  }

}
 <h2 class="page-header">Register</h2>
<form (submit)="onRegisterSubmit()">
  <div class="form-group">
    <label>Name</label>
    <input type="text" [(ngModel)]="name" name="name" class="form-control">
  </div>
  <div class="form-group">
    <label>Username</label>
    <input type="text" [(ngModel)]="username" name="username" class="form-control">
  </div>
  <div class="form-group">
    <label>Email</label>
    <input type="email" [(ngModel)]="email" name="email" class="form-control">
  </div>
  <div class="form-group">
    <label>Password</label>
    <input type="password" [(ngModel)]="password" name="password" class="form-control">
  </div>
  <input type="submit" class="btn btn-primary" value="Submit">
</form> 

return this.http.post('http://localhost:3000/users/register','user', {headers: headers})
return this.http.post('http://localhost:3000/users/register', user, {headers: headers})