Angular2-Recaptcha未在浏览器返回事件上加载

时间:2017-04-12 04:01:31

标签: node.js webpack-2 recaptcha typescript2.2 angular4.x

我在Angular Application工作。应用程序初始化后,Recaptcha工作正常。导航到下一页,同时按下浏览器后退按钮事件angular2-recaptcha未加载

在Package.json文件中我正在使用angular2-recaptcha

"dependencies": {
    "@angular/animations": "^4.0.1",
    "@angular/common": "^4.0.1",
    "@angular/compiler": "^4.0.1",
    "@angular/core": "^4.0.1",
    "@angular/forms": "^4.0.1",
    "@angular/http": "^4.0.1",
    "@angular/platform-browser": "^4.0.1",
    "@angular/platform-browser-dynamic": "^4.0.1",
    "@angular/router": "^4.0.1",
    "angular2-recaptcha": "^0.5.0",
    }

的login.html

<div>
<re-captcha (captchaResponse)="handleCorrectCaptcha($event)" [site_key]="siteKey" class="captcha"></re-captcha>
</div>

login.component.ts

import { ViewChild } from '@angular/core';
import { ReCaptchaComponent } from 'angular2-recaptcha';
 import { Router, RouterModule } from "@angular/router";

export class RegisterComponent {
  @ViewChild(ReCaptchaComponent) captcha: ReCaptchaComponent;
  constructor(private route: Router,private service:loginservice){
  }
  capcha:any; 
    handleCorrectCaptcha(response: string) {
     this.service.getCaptcha(response)
            .subscribe(
            res => {
            this.capcha=res;
             this.route.navigate(['/dashboard']);
            });
    }

}

模块

import { ReCaptchaModule } from 'angular2-recaptcha';

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

1 个答案:

答案 0 :(得分:1)

我认为当组件再次加载时,不会初始化site_key

使用APP_INITIALIZER初始化网站变量。

查看此link