npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-google-recaptcha

v1.0.3

Published

Easily use Google's reCAPTCHA within your Angular forms

Downloads

976

Readme

Google's reCAPTCHA is an awesome, UX-friendly way of ensuring that the users who are submitting your forms are actually humans.

Angular has fantastic built in forms functionality which makes it easy to write powerful custom components and validation logic.

This library makes it effortless to combine them!

If you ever need to reference the full reCAPTCHA docs you can find them here: reCAPTCHA docs

Installation

Head over to the command line and use your favourite package manager to install and save it as a dependency:

E.g.

npm install --save angular-google-recaptcha

or

yarn add angular-google-recaptcha

Usage

1. If you haven't yet registered your site for use with reCAPTCHA, you'll need to do that next.

Head over to:

https://www.google.com/recaptcha/admin#list

...and register your site.

Once you have done that, a "site key" will have been generated for you. You need to find this and copy it to you clipboard as it will be important in the next step!

2. Now all you need to do is pass that site key into the library, and this is done via the forRoot convention on the NgModule which the library exposes.

E.g.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { RecaptchaModule } from 'angular-google-recaptcha';

@NgModule({
    imports: [
        BrowserModule,
        ReactiveFormsModule,
        RecaptchaModule.forRoot({
            siteKey: 'YOUR_SITE_KEY_HERE',
        }),
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

As you might expect, you need to be using the @angular/forms package (either the FormsModule or ReactiveFormsModule) within your project, otherwise this library will have nothing to hook into.

3. With everything wired up, you can now use the <recaptcha> component!

E.g. For reactive forms

import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';

@Component({
    selector: 'app',
    template: `
        <recaptcha
          [formControl]="myRecaptcha"
          (scriptLoad)="onScriptLoad()"
          (scriptError)="onScriptError()"
        ></recaptcha>
    `
})
export class AppComponent {
    myRecaptcha = new FormControl(false);

    onScriptLoad() {
        console.log('Google reCAPTCHA loaded and is ready for use!')
    }

    onScriptError() {
        console.log('Something went long when loading the Google reCAPTCHA')
    }
}

E.g. For template-driven forms

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

@Component({
    selector: 'app',
    template: `
        <recaptcha
          [(ngModel)]="myRecaptcha"
          (scriptLoad)="onScriptLoad()"
          (scriptError)="onScriptError()"
        ></recaptcha>
    `
})
export class AppComponent {
    myRecaptcha: boolean

    onScriptLoad() {
        console.log('Google reCAPTCHA loaded and is ready for use!')
    }

    onScriptError() {
        console.log('Something went long when loading the Google reCAPTCHA')
    }
}