Angular - 努力处理图像 URL

Angular - Struggel with sanitization of Image 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})');