Angular 2 : TypeScript component for Google reCaptcha 2
This is just very simple Angular 2 component that implements Google reCaptcha 2.
Installation
Install it from npm:
npm install angular2-recaptcha
Usage
SystemJS config
System;
Module
...;...
... ...
View
Use in template like below
Where site_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 Either
light
(default) ordark
. - type Either
image
(default) oraudio
. - size Either
normal
(default),compact
orinvisible
. - tabindex Tabindex for navigation, default 0.
Callback
To catch the success callback, you will need to subscribe to the captchaResponse
event. The response token will be passed in the $event
parameter.
The event captchaExpired
is triggered when the displayed image has expired. It does not have any event parameters.
Methods
To access the methods, use @ViewChild.
Import
;;
Usage
You can request a new captcha to be displayed:
this.captcha.reset;
The previous response can be retrieved:
;