使用最新版本的ng-recaptcha并将recaptcha组件包装在一个字面上的数据对象中。
代码示例: 安装ng-recaptcha:
npm install ng-recaptcha --save
在app.module.ts中导入:
import { RecaptchaModule } from 'ng-recaptcha';
@NgModule({ imports: [ RecaptchaModule.forRoot(), // other modules... ], // declarations, providers, etc. })
在组件中使用:
import { RecaptchaComponent } from 'ng-recaptcha';
@Component({
selector: 'app-my-component',
template:
,
})
export class MyComponent { public myForm: FormGroup; public recaptcha: FormControl;
constructor(private fb: FormBuilder) { this.recaptcha = this.fb.control(null, Validators.required);
this.myForm = this.fb.group({
recaptcha: this.fb.group({
recaptcha: this.recaptcha,
}),
});
} }