Angularjs从纯JS函数调用$scope.function
Angularjs call $scope.function from plain JS function
我正在尝试实现一个谷歌重述,我能够在的帮助下验证用户是人类
reCapcha代码正在调用我的代码中名为"verifyCallback"的回调函数,此外,我想调用在我的控制器范围内编写的AngularJS函数。
这是我到目前为止的代码-
主Html,我已经包括-
<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
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>
AngularJS控制器-
var _myApp = angular.module('homeApp',[]);
_myApp.controller('loginController',['$scope',
function($scope){
$scope.auth = function()
{
console.log("Auth called");
}
}]);
<div ng-controller='loginController' id='yourControllerElementID'>
</div>
对于上述场景,使用以下代码:
var scope = angular.element(document.getElementById('yourControllerElementID')).scope();
scope.auth();
所以,你的方法看起来是这样的:
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();
};
相关文章:
- AngularJS:ng之后,重复$scope值未按预期更新
- 直接在函数声明上使用function.prototype.bind
- jQuery:.click(function(){(element),collapse('show',f
- $ionicplatform内的$scope不;不起作用
- 使用$scope方法时的ControllerAs语法
- 如何将ngrepeat下的ngmodel绑定到$scope
- 另一个if(!$scope.$$phase)$scope$apply()szenario-需要帮助才能通关
- 如果连接类型为none,则Javascript Function Only警报
- 使用AngularJS Directive WHITOUT$scope创建一个动态html元素
- $scope变量被视为字符串AngularJs
- Angularjs从纯JS函数调用$scope.function
- 什么's AngularJS中$scope.myScope=function()和function()之间的区别
- $scope.$watch(var,function) undefined 不是函数
- jQuery / JavaScript Function Scope / Hoisting
- AngularJS Access $scope in function
- 如何从href调用AngularJS$scope.Function
- 如何从$scope.function2调用$scope.function 1
- 为什么在v8::Scope之前创建新的v8::Array会导致分割错误,而v8::String和v8::Function
- AngularJS function and $scope
- Angular$scope未按预期工作.正在尝试在控制器$scope和$scope.function作用域中分配对象值