angular2-google-recaptcha
Version:
angular2-google-recaptcha is a simple congigurable angular2 directive
47 lines (37 loc) • 1.04 kB
text/typescript
import {Directive, ElementRef, EventEmitter, Input,Output, OnInit} from '@angular/core';
import {NgModel} from '@angular/common';
declare var grecaptcha: any;
({
selector: '[googlerecaptcha]',
providers: [NgModel],
host: {
'(input)' : 'onInputChange()'
}
})
export class GoogleRecaptchaDirective implements OnInit {
('theme') theme:string = '';
('siteKey') siteKey:string;
('setVerified') setVerified: EventEmitter<any> = new EventEmitter();
modelValue:any;
private _el:HTMLElement;
constructor(el: ElementRef,private model:NgModel) {
this._el = el.nativeElement;
this.modelValue = this.model;
var input = this._el;
}
ngOnInit() {
setTimeout(() =>{
grecaptcha.render(this._el, {
'sitekey' : this.siteKey,
'callback' : (data) => {
if(data) {
this.setVerified.emit(true);
}
},
'theme' : this.theme
});
},1000)
};
onInputChange() {
}
}