我一直在 html 字符串中使用 DomSanitizer 和 SVG。
在当前版本的 Angular 之前,这工作得很好:
this.domSanitizer.bypassSecurityTrustHtml(content);
现在我正在取回一个名为
SafeHtmlImpl {changingThisBreaksApplicationSecurity: "<svg> blah </svg>"}
changingThisBreaksApplicationSecurity
现在有新的方法来访问 DomSanitizer 的输出吗?我应该以 SafeHTML 类型还是其他类型接收它?如果bypassSecurityTrustHtml仍然过滤html,那么它还有什么意义呢?
明信片上有答案吗?请...
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>";
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)