• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Other / ReCaptcha in Angular

ReCaptcha in Angular

recaptcha.service.ts

import { Injectable } from '@angular/core';

import { environment } from '../../../environments/environment';

@Injectable({
providedIn: 'root'
})
export class RecaptchaService {
public loadRecaptchaScript(): void {
const script = document.createElement('script');
script.src = `https://www.google.com/recaptcha/api.js?render=${environment.recaptchaSiteKey}`;
script.async = true;
script.defer = true;

document.head.appendChild(script);
}
}

environment.ts

export const environment = {
recaptchaSiteKey: 'xxxxxxxxxxxxxxxx',
};

app.component.ts

private readonly _recaptchaService = inject(RecaptchaService);

public ngOnInit(): void {
if (isPlatformBrowser(this._platformId)) {
this._recaptchaService.loadRecaptchaScript();
}
}

Filed Under: Other

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved