我试图净化一个图像网址,但我不会为我工作...
这是我的代码
home.component.ts
constructor(public dialog: MatDialog, private route: ActivatedRoute, private sanitization : DomSanitizer) {
}
user: any;
img: SafeStyle;
ngOnInit(): void {
this.route.data.subscribe((data: {user: any}) => { this.user = data.user;});
console.log('Data: ', this.user);
this.img = this.sanitization.bypassSecurityTrustStyle('url(${this.user.profileImagePath})');
}home.component.html
<div class="create_post_avatar" ngIF='img'>
<img [src]='img'>
</div>你能帮帮我吗?
发布于 2020-10-16 20:33:16
尝试将清理方法更改为bypassSecurityTrustResourceUrl
this.img = this.sanitization.bypassSecurityTrustResourceUrl('url(${this.user.profileImagePath})');https://stackoverflow.com/questions/64389099
复制相似问题