captcha-com / angular-captcha

BotDetect CAPTCHA: Angular Captcha Module (TypeScript: Angular 2/4/5/6/7/8+).
https://captcha.com/angular-captcha.html
16 stars 10 forks source link

Not working with Angular 8 #5

Closed stephanecot closed 5 years ago

stephanecot commented 5 years ago

The error: Uncaught Error: Can't resolve all parameters for CorrectCaptchaDirective: (?, [object Object])...

It seams that the import: import { DOCUMENT } from '@angular/platform-browser';

has changed to: import { DOCUMENT } from '@angular/common';

botdetect-support commented 5 years ago

The issue is fixed in the Angular Captcha Module v3.6.0.

Run the following command to get the latest version:

npm i angular-captcha@latest

Thanks for reporting the issue! If you have any further questions, please feel free to contact us at: https://captcha.com/contact.html

stephanecot commented 5 years ago

There're still an error when compiling in prod mode:

Function calls are not supported in decorators but 'provideBotDetectCaptcha' was called in 'BotDetectCaptchaModule' 'BotDetectCaptchaModule' calls 'provideBotDetectCaptcha'.

botdetect-support commented 5 years ago

Thanks for your report. We are working on it and will notify you once the issue is fixed. To avoid this issue you can use the following approach:

After you import Angular Captcha Module in your app.module.ts:

// import the Angular Captcha Module 
import { BotDetectCaptchaModule } from 'angular-captcha'; 

@NgModule({
  imports: [
    ...
    BotDetectCaptchaModule
  ],
  ...
})

set the captchaEndpoint in your component:

import { CaptchaComponent } from 'angular-captcha'; 

export class YourFormWithCaptchaComponent {

  @ViewChild(CaptchaComponent, { static: true }) captchaComponent: CaptchaComponent;

  ngOnInit(): void {
    this.captchaComponent.captchaEndpoint = 
      // if you have asp.net on backend
      'https://your-app-backend-hostname.your-domain.com/simple-captcha-endpoint.ashx';

      // if you have java on backend
      // 'https://your-app-backend-hostname.your-domain.com/simple-captcha-endpoint';

      // if you have php on backend
      //'https://your-app-backend-hostname.your-domain.com/botdetect-captcha-lib/simple-botdetect.php';
  }
botdetect-support commented 5 years ago

@stephanecot The compilation issue is fixed in the Angular Captcha Module v3.7.1.

Run the following command to get the latest version:

npm i angular-captcha@latest

stephanecot commented 5 years ago

Thanks!

Le mer. 5 juin 2019 à 10:29, botdetect-support notifications@github.com a écrit :

Closed #5 https://github.com/captcha-com/angular-captcha/issues/5.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/captcha-com/angular-captcha/issues/5?email_source=notifications&email_token=ALXXLCGJEOXFP2JOPCNPDI3PY52PRA5CNFSM4HSGGTIKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGORZ53L3I#event-2390472173, or mute the thread https://github.com/notifications/unsubscribe-auth/ALXXLCDZIAIJF327QM757OTPY52PRANCNFSM4HSGGTIA .

stephanecot commented 5 years ago

It's working, but I found another smalll problem. I have a core module and some child modules.

You need to move the declaration of: providers: [ CaptchaService, CaptchaHelperService, CaptchaEndpointPipe, ..}

into the forRoot() method and not to keep them into the general module, because, it make mandatory to use the forChild() method for each features modules which used the captcha module.

If the forChild() method is not used (ie no config is set), the previous root config is never used as the services are re-created in the child.