angular - Json中的锚标记到HTML
问题描述
伙计们...
我有一个包含大量文本的 json 文件,用于国际化我的应用程序。在某些行中,我需要放置锚标签。我的问题是当 json 呈现为 HTML 时,锚标记无法正常工作。如您所见,我的锚标记中有一个 (click)="switchPage('something)' ,当我打开 html 代码所在的页面时,我在控制台上得到了这个:警告:清理 HTML 删除了一些内容,请参阅http://g.co/ng/security#xss。但是,如果我将(单击)更改为 href="something" 它工作正常。
我究竟做错了什么?无论如何提前谢谢!
JSON 行
"instructions": "Already a member? <a (click)='switchPage('signIn')>Sign-In now!</a>",
管道
export class SanitizePipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform (value: string): SafeHtml {
return this.sanitizer.sanitize(SecurityContext.HTML, this.sanitizer.bypassSecurityTrustHtml(value));
}
}
HTML
<p class="mat-small bit-of-space" id="result" [@vanish]="page" [innerHTML]="'login.pages.'+page+'.instructions' | translate | sanitizeHTML"></p>
解决方案
推荐阅读
- javascript - 表的 SAPUI5 数据绑定不起作用
- bash - 如何使用 sed 替换“word{word”或“word}word”
- angular - 特定组件的Angular 6单元测试错误
- git - 有什么方法可以从 `index` 和 `objects` 恢复 git 提交(或完整的 repo)?
- rest - 在未经身份验证的情况下使用 SPA 时保护 REST API 的使用
- python-3.x - 在python tkinter中恢复画布上已删除的图片
- c - 如何为C中的字符串分配动态内存区域
- powershell - 如何将 RTF 文档转换为 docx
- linux - 即使在 `sort` 之后,`uniq` 仍然重复一些值
- c# - Passing parameters from textboxes to sql statement string - single quotes (') killing me