I need to integrate reCaptchaV3 so I followed the ng-recaptcha-npm
Here is the base code that I implemented with the help of the ng-recaptcha-npm
.
MyModule
import { RecaptchaV3Module, RECAPTCHA_V3_SITE_KEY } from 'ng-recaptcha';
imports: [
...
RecaptchaV3Module
],
providers: [
AuthResolver,
{ provide: RECAPTCHA_V3_SITE_KEY, useValue: environment.RECAPTCHA_KEY }
]
MyComponent
import { ReCaptchaV3Service } from 'ng-recaptcha';
constructor(
...
private recaptchaV3Service: ReCaptchaV3Service
) {}
public onSendClicked(): void {
this.recaptchaV3Service.execute('importantAction')
.subscribe((token) => {
console.log('token = ', token);
});
But it returns a bad response and here is the console error.
NullInjectorError: No provider for ReCaptchaV3Service!
NullInjectorError: R3InjectorError(AppModule)[ReCaptchaV3Service -> ReCaptchaV3Service -> ReCaptchaV3Service]:
NullInjectorError: No provider for ReCaptchaV3Service!
at NullInjector.get (core.js:1085)
at R3Injector.get (core.js:16968)
at R3Injector.get (core.js:16968)
at R3Injector.get (core.js:16968)
at NgModuleRef$1.get (core.js:36342)
at Object.get (core.js:33985)
at getOrCreateInjectable (core.js:5848)
at Module.ɵɵdirectiveInject (core.js:21116)
at NodeInjectorFactory.ContactUsComponent_Factory [as factory] (contact-us.component.ts:19)
at getNodeInjectable (core.js:5993)
at resolvePromise (zone-evergreen.js:798)
at resolvePromise (zone-evergreen.js:750)
at zone-evergreen.js:860
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:41645)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at drainMicroTaskQueue (zone-evergreen.js:569)
add ReCaptchaV3Service in provider
import { ReCaptchaV3Service } from 'ng-recaptcha';
imports: [
...
RecaptchaV3Module
],
providers: [
ReCaptchaV3Service,
AuthResolver,
{ provide: RECAPTCHA_V3_SITE_KEY, useValue: environment.RECAPTCHA_KEY }
]