代码之家  ›  专栏  ›  技术社区  ›  Bluebaron

名为“recaptchaReactive”的窗体控件没有值访问器

  •  0
  • Bluebaron  · 技术社区  · 7 年前

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

    email字段(以及我省略的密码)起作用。 在组件中,我有以下内容。

    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 回复  |  直到 7 年前
        1
  •  2
  •   yurzui    7 年前

    看起来你忘记导入了 RecaptchaFormsModule

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