首页 > 解决方案 > 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>

标签: angular

解决方案


推荐阅读