没有名称为'recaptchaReactive'的表单控件的值访问器

时间:2018-11-27 03:50:22

标签: angular

从此示例https://stackblitz.com/edit/ng-recaptcha-example?file=src%2Fapp%2Fapp.component.ts

开始工作

可能与以下内容有关:Angular4 - No value accessor for form control

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

<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)
});

1 个答案:

答案 0 :(得分:1)

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

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