【问题标题】:WARNING: sanitizing HTML stripped some content, see http://g.co/ng/security#xss警告:清理 HTML 会删除一些内容,请参阅 http://g.co/ng/security#xss
【发布时间】:2020-01-26 08:35:54
【问题描述】:

我在我的角度示例中收到这样的警告。

警告:清理 HTML 会删除一些内容,请参阅 http://g.co/ng/security#xss

Stackblitz:https://stackblitz.com/edit/angular-e4otvr-mjm48m?file=app.component.ts

请有人帮我离开这里。

提前致谢。

我已经尝试过这个解决方案。

https://blog.angularindepth.com/warning-sanitizing-html-stripped-some-content-and-how-to-deal-with-it-properly-10ff77012d5a

仍然出现警告。

getCellContent(e): string {


    if (e && e.targetCell.className.indexOf('e-valuescontent') > -1 ) {
        template = '<input type="checkbox">'; //Here,  you can append the html elements

    }
     else {
        template = '';
     }

    return this.sanitizer.sanitize(SecurityContext.HTML, template) || '';
}

警告:清理 HTML 会删除一些内容,请参阅 http://g.co/ng/security#xss

【问题讨论】:

    标签: javascript angular angular2-template


    【解决方案1】:

    你试过了吗?

    return this.sanitizer.bypassSecurityTrustHtml(template);
    

    而不是

    return this.sanitizer.sanitize(SecurityContext.HTML, template) || '';
    

    Angular 需要信任您通过 innerHTML 插入的 html。这个bypassSecurityTrustHtml(template) 方法会有所帮助。它对我有用。让我知道你的。

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      相关资源
      最近更新 更多