Google NoCaptcha ReCaptcha only shows up on refresh in Angular SPA

我与影子孤独终老i 提交于 2019-12-05 17:53:49

I ended up using vc-recaptcha to get this working.

Setup is pretty simple and it is updated fairly regularly.

This answer works for me with the new reCaptcha (I'm not a robot)

in Html (be sure to insert it within a form tag):

 <recaptcha></recaptcha>

Directive Code

angular.module('app').directive('recaptcha',['$window','$compile',function($window, $compile) {
  return {
    replace: true,
    link: function(scope, elem){
      var key = 'xxxxxxxxxxxxxxxxxxxxx';          <--<your public key
      activate();
      function activate(){
      if (angular.isDefined($window.grecaptcha)) {        
           $window.grecaptcha.render(elem[0],{
             'sitekey': key
             });           
        } else {
          activate();  **<- no good -> use some kind of promise here, just for testing**
        }
      }
    }          
  };
}]);

In old recpatche it is some kind of

  $window.grecaptcha.render(elem[0], key);   

Check API documentation for that.

Check here: http://www.codedodle.com/2014/12/google-new-recaptcha-using-javascript.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!