名称为 'recaptchaReactive' 的窗体控件没有值访问器



从这个例子开始工作https://stackblitz.com/edit/ng-recaptcha-example?file=src%2Fapp%2Fapp.component.ts

可能与以下内容有关:Angular4-表单控制无值访问器

在我的表格中,我有以下内容。

<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<mat-form-field class="example-full-width">
<input matInput placeholder="{{'Email' | translate}}" formControlName="email"                                        [errorStateMatcher]="matcher">
<mat-error *ngIf="loginForm.controls['email'].hasError('email') || loginForm.controls['email'].hasError('required')">
{{"Enter a valid email address" | translate}}
</mat-error>
</mat-form-field>
<re-captcha formControlName="recaptchaReactive"></re-captcha>
</form>

电子邮件字段(以及我省略的密码(确实有效。在组件中,我有以下内容。

loginForm = new FormGroup({
email: new FormControl('', [
Validators.email,
Validators.required
]),
password: new FormControl('', [
Validators.required,
Validators.minLength(8)
]),
recaptchaReactive: new FormControl(null, Validators.required)
});

您似乎忘记在NgModule:中导入RecaptchaFormsModule

@NgModule({
imports: [
RecaptchaModule,
RecaptchaFormsModule, <== required when working with forms
],
...
})
export class AppModule { }

最新更新