Safe value must use [property]=binding after bypass security with DomSanitizer

前端 未结 5 1151
我寻月下人不归
我寻月下人不归 2020-12-05 13:18



        
5条回答
  •  清歌不尽
    2020-12-05 13:45

    I got a same error while using MATHJAX in angular 7. I resolved by below pipe transform. 100% work perfectly

    //Sanitize HTML PIPE

    import { Pipe, PipeTransform, SecurityContext } from "@angular/core";
    import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
    
    @Pipe({
        name: 'sanitizeHtml'
    })
    export class SanitizeHtmlPipe implements PipeTransform {
    
        constructor(private _sanitizer: DomSanitizer) {
        }
    
        transform(value: string): SafeHtml {
            return this._sanitizer.sanitize(SecurityContext.HTML, this._sanitizer.bypassSecurityTrustHtml(value))
        }
    }
    

提交回复
热议问题