NetanelBasal
6/4/2017 - 6:08 PM

recaptcha7.directive.ts

export class ReCaptchaDirective implements OnInit, AfterViewInit, ControlValueAccessor {

  constructor( private element : ElementRef, private  ngZone : NgZone, private injector : Injector, private reCaptchaAsyncValidator : ReCaptchaAsyncValidator ) {
  }

  onSuccess( token : string ) {
    this.ngZone.run(() => {
      this.verifyToken(token);
      this.onChange(token);
      this.onTouched(token);
    });
  }

  verifyToken( token : string ) {
    this.control.setAsyncValidators(this.reCaptchaAsyncValidator.validateToken(token))
    this.control.updateValueAndValidity();
  }

}