Angular 2 disable sanitize

后端 未结 3 584
野的像风
野的像风 2020-12-04 02:21

I am trying to render base64 string into .

But always when I try to render it, ng2 sanitizing my base64 str

3条回答
  •  离开以前
    2020-12-04 02:50

    You need to explicitly tell Angular2 that the string is trusted

    https://angular.io/docs/ts/latest/api/platform-browser/index/DomSanitizer-class.html

    constructor(private sanitizer:DomSanitizer) {}
    
    get imgBase64() {
      this.sanitizer.bypassSecurityTrustUrl('data:image/png;base64,$SomeBase64StringFetchedSomehow');
    }
    
    RegularImage
    

    See also In RC.1 some styles can't be added using binding syntax

提交回复
热议问题