调用AngularJS内部<脚本>标签
Calling AngularJS inside <script> tag
我有这个指令:
function Recaptcha(RecaptchaService) {
return {
restrict: 'E',
templateUrl: 'app/components/login/recaptcha.html',
controller: function($scope) {
$scope.sendResp = function(response) {
RecaptchaService.sendResponse(response);
};
}
}
}
使用模板登录/重述a:
<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
。有办法做到这一点吗?
试试这个
(只有当captchadiv在ng应用程序中时,这才有效)
<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>
相关文章:
- 如何逃离<脚本>jquery html()中的标记.我使用了innerHTML和outerHTML来解决这个
- </脚本>标签放错地方了
- 内联javascript与"<脚本>"字符串错误地关闭了脚本标记
- "未捕获类型错误/丢弃意外“;因为一句台词而出现?(HTML w/<脚本>)
- 在<script src=“"></脚本>标签
- 使用几个<脚本>标签不会't工作-只调用一个脚本
- 等效于<script src=“;something1.json”></脚本>
- 我如何访问传递给<脚本>标记
- 运行一个特定<脚本>(Dreamweaver)
- 是否在Script Src标记中包含Script<脚本>(JavaScript等)
- VS代码:在<脚本>标签
- 是否可以添加<脚本>添加'_someTag'到iFrame中的URL
- 优化J$plus组合3<脚本>转换为1
- Meteor.js:<脚本>标签不't在<身体>
- 我的代码在<脚本>标记,但没有'不能在外部文件中工作
- 显示“<script src='some.js'></脚本>"在Html文档中
- 有没有一种方法可以使用<脚本>标记为您可能使用的<%%>标记
- 注入<脚本>标签给它一个合适的位置
- Eloqua替换<脚本>标签
- 选择<脚本></脚本>作为html正文中的纯文本