【问题标题】:No value accessor for form control with name: 'recaptchaReactive'名称为“recaptchaReactive”的表单控件没有值访问器
【发布时间】:2018-11-27 03:50:21
【问题描述】:

从这个例子开始工作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)
});

【问题讨论】:

    标签: angular


    【解决方案1】:

    您好像忘记在 NgModule 中导入 RecaptchaFormsModule

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

    【讨论】:

      猜你喜欢
      • 2018-06-07
      • 2023-04-08
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多