Skip to content

Commit

Permalink
chore: swap to using afterNextRender (#43)
Browse files Browse the repository at this point in the history
* chore: swap to using afterNextRender

* apply code review changes

Co-authored-by: Aleksander Bodurri <alexbodurri1117@gmail.com>

---------

Co-authored-by: Aleksander Bodurri <alexbodurri1117@gmail.com>
  • Loading branch information
AhmedHalat and AleksanderBodurri authored Sep 24, 2024
1 parent 4d2e171 commit 356b276
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions projects/ngx-turnstile/src/lib/ngx-turnstile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EventEmitter,
OnDestroy,
Inject,
afterNextRender,
} from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { TurnstileOptions } from './interfaces/turnstile-options';
Expand Down Expand Up @@ -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;
Expand All @@ -57,7 +58,9 @@ export class NgxTurnstileComponent implements AfterViewInit, OnDestroy {
private elementRef: ElementRef<HTMLElement>,
private zone: NgZone,
@Inject(DOCUMENT) private document: Document,
) {}
) {
afterNextRender(() => this.createWidget());
}

private _getCloudflareTurnstileUrl(): string {
if (this.version === '0') {
Expand All @@ -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,
Expand Down

0 comments on commit 356b276

Please # to comment.