Ani*_*aje 5 javascript recaptcha angularjs
我正在尝试实施一个google recapcha,我能够在它的帮助下验证用户是人,
reCapcha代码在我的代码中调用名为'verifyCallback'的回调函数.此外,我想调用在我的控制器范围内编写的AngularJS函数.
这是我目前的代码 -
主要的Html,我已经包括 -
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
Run Code Online (Sandbox Code Playgroud)
Html偏 -
var onloadCallback = function()
{
grecaptcha.render('loginCapcha', {
'sitekey' : 'someKey',
'callback' : verifyCallback,
'theme':'dark'
});
};
var verifyCallback = function(response)
{
//I get a response if user is able to solve the Capcha challenge
console.log(response);
//I want to call the function called 'auth' written in my AngularJS controller
var scope = angular.element(document.getElementById('#loginCapcha')).scope();
scope.auth();
};
<div id="loginCapcha"></div>
Run Code Online (Sandbox Code Playgroud)
AngularJS控制器 -
var _myApp = angular.module('homeApp',[]);
_myApp.controller('loginController',['$scope',
function($scope){
$scope.auth = function()
{
console.log("Auth called");
}
}]);
Run Code Online (Sandbox Code Playgroud)
<div ng-controller='loginController' id='yourControllerElementID'>
</div>
Run Code Online (Sandbox Code Playgroud)
对于上述场景,请使用以下代码:
var scope = angular.element(document.getElementById('yourControllerElementID')).scope();
scope.auth();
Run Code Online (Sandbox Code Playgroud)
所以,你的方法将如下所示:
var verifyCallback = function(response)
{
//I get a response if user is able to solve the Capcha challenge
console.log(response);
//I want to call the function called 'auth' written in my AngularJS controller
var scope = angular.element(document.getElementById('#yourControllerElementID')).scope();
scope.auth();
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3712 次 |
| 最近记录: |