[英]Calling AngularJS inside <script> tag
I have this directive: 我有这个指令:
function Recaptcha(RecaptchaService) {
return {
restrict: 'E',
templateUrl: 'app/components/login/recaptcha.html',
controller: function($scope) {
$scope.sendResp = function(response) {
RecaptchaService.sendResponse(response);
};
}
}
}
With the template login/recaptcha : 使用模板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>
So, I want to call $scope.sendResp
inside my <script>
. 因此,我想在我的
<script>
调用$scope.sendResp
。 But I'm getting $scope is not defined
. 但是我得到
$scope is not defined
。 Is there a way to do that? 有没有办法做到这一点?
Try this.. 尝试这个..
(This works only when the captcha div is inside ng-app) (仅当验证码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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.