diff --git a/projects/ngx-turnstile/src/lib/ngx-turnstile.component.ts b/projects/ngx-turnstile/src/lib/ngx-turnstile.component.ts index 71dc344..4641f0d 100644 --- a/projects/ngx-turnstile/src/lib/ngx-turnstile.component.ts +++ b/projects/ngx-turnstile/src/lib/ngx-turnstile.component.ts @@ -8,6 +8,7 @@ import { EventEmitter, OnDestroy, Inject, + afterNextRender, } from '@angular/core'; import { DOCUMENT } from '@angular/common'; import { TurnstileOptions } from './interfaces/turnstile-options'; @@ -38,7 +39,7 @@ type SupportedVersion = '0'; template: ``, exportAs: 'ngx-turnstile', }) -export class NgxTurnstileComponent implements AfterViewInit, OnDestroy { +export class NgxTurnstileComponent implements OnDestroy { @Input() siteKey!: string; @Input() action?: string; @Input() cData?: string; @@ -57,7 +58,9 @@ export class NgxTurnstileComponent implements AfterViewInit, OnDestroy { private elementRef: ElementRef, private zone: NgZone, @Inject(DOCUMENT) private document: Document, - ) {} + ) { + afterNextRender(() => this.createWidget()); + } private _getCloudflareTurnstileUrl(): string { if (this.version === '0') { @@ -67,7 +70,7 @@ export class NgxTurnstileComponent implements AfterViewInit, OnDestroy { throw 'Version not defined in ngx-turnstile component.'; } - public ngAfterViewInit(): void { + public createWidget(): void { let turnstileOptions: TurnstileOptions = { sitekey: this.siteKey, theme: this.theme,