使用谷歌的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包。任何人都可以帮忙吗?
答案 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"])