2016-10-04 5 views
12

私は、HTML文字列にSVGでDomSanitizerを使用しています。角2、DomSanitizer、bypassSecurityTrustHtml、SVG

角度の現在のバージョン前へ

が、これはうまく働いていた:

this.domSanitizer.bypassSecurityTrustHtml(content);

を今私は戻って

SafeHtmlImpl {changingThisBreaksApplicationSecurity: "<svg> blah </svg>"} 
changingThisBreaksApplicationSecurity 

と呼ばれるオブジェクトを取得していますと、今にアクセスするための新しい方法がありますDomSanitizerの出力?私はそれをSafeHTMLのようなものとして受け取るべきでしょうか? bypassをまだ持っている場合、bypassSecurityTrustHtmlを持っている点は何ですか?

はがきの回答はありますか?してください...

+0

だから、問題は何ですか? – micronyks

答えて

23

DEMO:https://plnkr.co/edit/Qke2jktna55h40ubUl8o?p=preview

import { DomSanitizer } from '@angular/platform-browser' 

@Pipe({ name: 'safeHtml'}) 
export class SafeHtmlPipe implements PipeTransform { 
    constructor(private sanitized: DomSanitizer) {} 
    transform(value) { 
    console.log(this.sanitized.bypassSecurityTrustHtml(value)) 
    return this.sanitized.bypassSecurityTrustHtml(value); 
    } 
} 

@Component({ 
    selector: 'my-app', 
    template: ` 
    <div [innerHtml]="html | safeHtml"> 
    </div> 
    `, 
}) 
export class App { 
    name:string; 
    html: safeHtml; 
    constructor() { 
    this.name = 'Angular2' 
    this.html = "<svg> blah </svg>"; 
    } 
} 
+0

私はそれを動作させるためにあなたのsvgを他のsvgに変更しました。 – micronyks

+0

ありがとうございます。パイプについての良いアイデア、私はそれを設定し、動作しました。機能的には何もしていませんが、誰が不平を言うのですか?できます。 – Tom

+0

誰が苦情を申し立てていますか? – micronyks