Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Angular 2 : Typescript component for Google reCaptcha

License

NotificationsYou must be signed in to change notification settings

xmaestro/angular2-recaptcha

Repository files navigation

Travis

Angular 2 : TypeScript component for Google reCaptcha 2

This is just very simple Angular 2 component that implements GooglereCaptcha 2.

Installation

Install it from npm:

npm install angular2-recaptcha

Usage

SystemJS config

System.config({map:{'angular2-recaptcha':'node_modules/angular2-recaptcha'},packages:{app:{format:'register',defaultExtension:'js'},'angular2-recaptcha':{defaultExtension:'js',main:'index'}}});

Module

...import{ReCaptchaModule}from'angular2-recaptcha';...
 ...@NgModule({imports:[...,ReCaptchaModule]})  ...

View

Use in template like below

<re-captchasite_key="<GOOGLE_RECAPTCHA_KEY>"></re-captcha>

Wheresite_key is the Google reCaptcha public key. Optional parameters as follows:

  • language One of the ISO language values supported by Google:https://developers.google.com/recaptcha/docs/language Note that due to the design of the reCaptcha API, only the first component on a page can change the language from default English.
  • theme Eitherlight (default) ordark.
  • type Eitherimage (default) oraudio.
  • size Eithernormal (default),compact orinvisible.
  • tabindex Tabindex for navigation, default 0.
  • global If true, the reCaptcha script will be loaded fromwww.recaptcha.net instead ofwww.google.com

Callback

To catch the success callback, you will need to subscribe to thecaptchaResponse event. The response token will be passed in the$event parameter.To wait for component to be loaded subscribe toloaded event.

<re-captcha(captchaResponse)="handleCorrectCaptcha($event)"(loaded)="sendCaptchaExecuteHere()"site_key="<GOOGLE_RECAPTCHA_KEY>"></re-captcha>

The eventcaptchaExpired is triggered when the displayed image has expired. It does not have any event parameters.

Methods

To access the methods, use@ViewChild.

Import

import{ViewChild}from'@angular/core';import{ReCaptchaComponent}from'angular2-recaptcha';exportclassRegisterComponent{  @ViewChild(ReCaptchaComponent)captcha:ReCaptchaComponent;}

Usage

You can request a new captcha to be displayed:

this.captcha.reset();

The previous response can be retrieved:

lettoken=this.captcha.getResponse();

About

Angular 2 : Typescript component for Google reCaptcha

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp