diff --git a/projects/ngx-captcha-lib/src/lib/components/invisible-recaptcha.component.ts b/projects/ngx-captcha-lib/src/lib/components/invisible-recaptcha.component.ts index d032655..c05425f 100644 --- a/projects/ngx-captcha-lib/src/lib/components/invisible-recaptcha.component.ts +++ b/projects/ngx-captcha-lib/src/lib/components/invisible-recaptcha.component.ts @@ -64,7 +64,7 @@ export class InvisibleReCaptchaComponent extends BaseReCaptchaComponent implemen */ execute(): void { // execute captcha - this.reCaptchaApi.execute(this.captchaId); + this.zone.runOutsideAngular(() => this.reCaptchaApi.execute(this.captchaId)); } protected captchaSpecificSetup(): void { diff --git a/projects/ngx-captcha-lib/src/lib/services/recaptcha_v3.service.ts b/projects/ngx-captcha-lib/src/lib/services/recaptcha_v3.service.ts index 4f993b8..80e8a2e 100644 --- a/projects/ngx-captcha-lib/src/lib/services/recaptcha_v3.service.ts +++ b/projects/ngx-captcha-lib/src/lib/services/recaptcha_v3.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable, NgZone } from '@angular/core'; import { ScriptService } from './script.service'; @@ -6,7 +6,8 @@ import { ScriptService } from './script.service'; export class ReCaptchaV3Service { constructor( - protected scriptService: ScriptService + protected scriptService: ScriptService, + protected zone: NgZone ) { } @@ -21,10 +22,12 @@ export class ReCaptchaV3Service { */ execute(siteKey: string, action: string, callback: (token: string) => void): void { this.scriptService.registerCaptchaScript(siteKey, (grecaptcha) => { - grecaptcha.execute(siteKey, { - action: action - }).then((token) => { - callback(token); + this.zone.runOutsideAngular(() => { + grecaptcha.execute(siteKey, { + action: action + }).then((token) => { + this.zone.run(() => callback(token)); + }); }); }); }