angular - 仅在 Angular 的登录组件中显示 reCaptcha V3
问题描述
我有一个Angular应用程序。我正在尝试在我的登录页面中添加reCaptcha V3 。
一切正常,但recaptcha 徽章显示在我的应用程序的所有页面中。我只需要显示 recaptcha 徽章登录页面。
我将脚本包含在我的index.html中
<script src="https://www.google.com/recaptcha/api.js?render=MYSITEKEY"></script>
我的login.component.ts
declare var grecaptcha: any;
export class LoginComponent implements OnInit {
private REC_SITEKEY= environment.REC_SITEKEY;
ngOnInit() {
grecaptcha.ready(() => {
grecaptcha.execute(this.REC_SITEKEY, { action: 'validate_captcha' }).then((token) => {
this.rec_response=token;
});
});
}
}
我知道我在index.html中调用脚本。所以徽章显示在所有页面中。但我尝试将脚本包含在login.component.html中。但它不起作用。
所以我需要隐藏除登录组件之外的所有页面的徽章。 我怎样才能做到这一点?
解决方案
推荐阅读
- angular - 为什么注入不适用于抽象?
- vb.net - Visual Studio 2019,如何在我的软件安装中包含 Access 数据库引擎?
- python - 如何从 DatetimeIndex 获取 Isoweek
- python - 为什么在 google colab 中出现名称错误?
- vba - 通过 VBA 访问添加到现有的直通查询
- android - 如何在 Compose 应用程序中请求权限?
- android - 需要将Adapter绑定到RecyclerView两次才能出现数据
- r - 使用 R Markdown 将 xls 文件加载到 R 时出现问题
- javascript - 为什么我不能使用左手赋值来修改函数结果的值?
- mongodb - 按对象数组对文档进行分组