从这个例子开始工作 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) });
看起来你忘记导入了 RecaptchaFormsModule
RecaptchaFormsModule
@NgModule({ imports: [ RecaptchaModule, RecaptchaFormsModule, <== required when working with forms ], ... }) export class AppModule { }