Angular 响应式表单:如何使表单值不进入后端

Angular Reactive Forms: How to make a form value not going backend

我正在实施注册表单(反应式)。其中我有密码和确认密码。我正在验证这两个字段,但在提交时我只想将密码字段转到 spring 引导。有人知道怎么做吗?

//registration.ts

 registrationForm: FormGroup;
  constructor(private fb: FormBuilder,private authService: AuthService, private router: Router) {}

  ngOnInit() {
    this.registrationForm = this.fb.group({
      fullname: ["", [Validators.required, Validators.minLength(5)]],
      emailId: ["", [Validators.required, Validators.minLength(5)]],
      password: [null, Validators.required],
      confirmPassword: [null, Validators.required],
      phoneNumber: [null, Validators.required],
      enabled: [true],
      roles:this.fb.array([{'role':'ADMIN'}]),
  
      address: this.fb.group({
        city: [""],
        state: [""],
        country: [""],
        postalCode: [""],
      }),
    },
    //{ validator: this.ConfirmPasswordValidator("password", "confirmPassword")}
    { validator: this.checkPasswords}
    
    );

  }

  checkPasswords (group : FormGroup) {
    let pass = group.get('password').value;
    let confirmPass = group.get('confirmPassword').value
    return pass === confirmPass ? null : { passwordNotSame: true } 
  }

RegisterUser(form: NgForm) {
    this.authService.register(form)
    .subscribe(
      result => {
        if (result.token) {
          localStorage.setItem('token', result.token)
          this.router.navigate(['dashboard'])
        }
      }
    )
  }


任何人都请提供一些想法。我是 angular

的新手

然后从 FormGroup 中删除特定值,如下所示。希望它会起作用

RegisterUser(form: NgForm) {

    delete this.registerForm.value.confirmPassword;
    this.authService.register(form)
    .subscribe(
      result => {
        if (result.token) {
          localStorage.setItem('token', result.token)
          this.router.navigate(['dashboard'])
        }
      }
    )
  }

不是Angular,而是Javascript

添加

RegisterUser(form: NgForm) {
const {confirmPassword, ...rest } = form;
    this.authService.register(rest)
    .subscribe(