【发布时间】:2018-10-14 15:19:51
【问题描述】:
我正在尝试使用 .NET Core 创建 Angular 5 注册表单。
我正在检查注册表中的密码和重新输入的密码是否相同。我正在使用 FormBuilder 作为表单。
但是检查密码 1 和密码 2 总是失败。我也试过===。
if (this.RegistrationForm.valid) {
if (this.RegistrationForm.get('password1') == this.RegistrationForm.get('password2')) {
this.MyService.Register(this.RegistrationForm.value).subscribe((data) => {}, error => this.errorMessage = error)
} else {
this.errorMessage = "cdscs";
}
}
constructor(private fb: FormBuilder, private MyService: RoadSignService) {
this.RegistrationForm = this.fb.group({
Id: 0,
name: ['', [Validators.required]],
email: ['', [Validators.required]],
gender: ['', [Validators.required]],
department: ['', [Validators.required]],
address: ['', [Validators.required]],
password1: ['', [Validators.required]],
password2: ['', [Validators.required]]
})
}
【问题讨论】:
-
我试过了。但没有任何帮助
-
请
console.log(this.RegistrationForm.get('password1'), this.RegistrationForm.get('password2'));并在此处发布结果。 -
你需要先用console.log 调试,做那行,检查有什么问题,可能是多余的空间。
console.log(this.RegistrationForm.get('password1'), this.RegistrationForm.get('password2'), this.RegistrationForm.get('password1') == this.RegistrationForm.get('password2')) -
你能发布你的 HTML 和 formbuilder 代码吗?
标签: angular typescript angular-formbuilder