如何解决Angular-清理图像URL的努力
我尝试对图像URL进行清理,但是我将无法为我服务...
这是我的代码
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>
你能帮我吗?
解决方法
尝试将消毒方法更改为bypassSecurityTrustResourceUrl
this.img = this.sanitization.bypassSecurityTrustResourceUrl('url(${this.user.profileImagePath})');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。