我有这个指令:
function Recaptcha(RecaptchaService) {
return {
restrict: 'E',
templateUrl: 'app/components/login/recaptcha.html',
controller: function($scope) {
$scope.sendResp = function(response) {
RecaptchaService.sendResponse(response);
};
}
}
}
使用模板login / recaptcha:
<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>
所以,我想在$scope.sendResp
内拨打<script>
。但我得到了$scope is not defined
。有没有办法做到这一点?
答案 0 :(得分:4)
试试这个..
(仅当验证码div在ng-app内时才有效)
<script type="text/javascript">
var verifyCallback = function(response) {
var el = document.querySelector('.g-recaptcha'),
$el = angular.element(el),
$scope = $el.scope();
$scope && $scope.sendResp(response);
};
</script>