AngularJS + reCaptcha:错误" reCaptcha尚未加载"

时间:2016-03-16 23:31:29

标签: angularjs

使用谷歌的Error: reCaptcha has not been loaded yet.软件包后,我获得了angular-recaptcha

index.html如下所示,显示recaptcha和在控制器中调用login函数的按钮显示正常。和recaptcha也很好。

<div vc-recaptcha class="g-recaptcha" data-sitekey="key"></div>
<div ng-click="lc.login()">submit</div>

app.js

(function () {
    'use strict';
    angular
        .module('loginService', [
            'vcRecaptcha'
        ]);
})();

controller如下,错误来自此处。看起来我没有正确注入recaptcha模块。

(function () {
    'use strict';
    angular
        .module('loginService.login.controllers')
        .controller('LoginController',
        ['$scope',
            'vcRecaptchaService',
            function ($scope, vcRecaptchaService) {
               var lc = this;
...
...
           function login() {
             if(vcRecaptchaService.getResponse() === "") // error is from here
 {...}

}]);

看来我没有以正确的方式注入recaptcha包。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

您是否按以下方式加载了库?

<script src="//www.google.com/recaptcha/api.js?render=explicit&onload=vcRecaptchaApiLoaded" async defer></script>
<script src="./angular-recaptcha.js"></script>
<script>
        var app = angular.module('loginService', ['vcRecaptcha']);
        // code
</script>

看一下示例和文档:

loginService添加到loginService.login.controllers

angular.module('loginService.login.controllers', ["loginService"])