Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jameshenry/angular-google-recaptcha
:sparkles: Easily use Google's reCAPTCHA within your Angular forms
https://github.com/jameshenry/angular-google-recaptcha
angular form forms google recaptcha typescript
Last synced: 11 days ago
JSON representation
:sparkles: Easily use Google's reCAPTCHA within your Angular forms
- Host: GitHub
- URL: https://github.com/jameshenry/angular-google-recaptcha
- Owner: JamesHenry
- License: mit
- Created: 2017-11-15T21:08:37.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-27T15:08:07.000Z (over 6 years ago)
- Last Synced: 2024-10-04T16:38:41.205Z (about 2 months ago)
- Topics: angular, form, forms, google, recaptcha, typescript
- Language: TypeScript
- Homepage: https://jameshenry.blog
- Size: 66.4 KB
- Stars: 11
- Watchers: 3
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Angular Google reCAPTCHA
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](https://developers.google.com/recaptcha/)
# Installation
Head over to the command line and use your favourite package manager to install and save it as a dependency:
E.g.
```bash
npm install --save angular-google-recaptcha
```or
```bash
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](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.
```ts
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 `` component!
E.g. For reactive forms
```ts
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';@Component({
selector: 'app',
template: `
`
})
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
```ts
import { Component } from '@angular/core';@Component({
selector: 'app',
template: `
`
})
export class AppComponent {
myRecaptcha: booleanonScriptLoad() {
console.log('Google reCAPTCHA loaded and is ready for use!')
}onScriptError() {
console.log('Something went long when loading the Google reCAPTCHA')
}
}
```