【发布时间】:2015-05-04 04:44:42
【问题描述】:
我有这个指令:
function Recaptcha(RecaptchaService) {
return {
restrict: 'E',
templateUrl: 'app/components/login/recaptcha.html',
controller: function($scope) {
$scope.sendResp = function(response) {
RecaptchaService.sendResponse(response);
};
}
}
}
使用模板登录/验证码:
<script src='https://www.google.com/recaptcha/api.js'></script>
<script type="text/javascript">
var verifyCallback = function(response) {
$scope.sendResp(response);
};
</script>
<div class="g-recaptcha" data-sitekey="MY-KEY" data-callback="verifyCallback"></div>
所以,我想在我的<script> 中调用$scope.sendResp。但我收到$scope is not defined。有没有办法做到这一点?
【问题讨论】:
-
将
verifyCallback添加到控制器并将引用传递给$scope? stackoverflow.com/questions/16881478/… -
不行,已经试过了
-
你的意思是 $scope.verifyCallback 在指令中,并在 data-callback 中调用它,对吗? @Pogrindis
-
据我所知,您无法在模块外访问 $scope。
标签: javascript angularjs angularjs-directive