【问题标题】:Angular - Struggel with sanitization of Image URLAngular - 努力清理图像 URL
【发布时间】:2020-10-16 12:21:23
【问题描述】:

我尝试清理图像 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>

你能帮帮我吗?

【问题讨论】:

    标签: angular sanitization


    【解决方案1】:

    尝试将清理方法更改为bypassSecurityTrustResourceUrl

    this.img = this.sanitization.bypassSecurityTrustResourceUrl('url(${this.user.profileImagePath})');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 2022-10-02
      • 1970-01-01
      • 2016-01-25
      • 2013-03-12
      • 2021-02-23
      • 2011-12-30
      相关资源
      最近更新 更多