0

I try to Sanitize a Image URL but i will not work for me...

This is my code

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>

Can you please help me?

1 Answer 1

0

Try to change sanitization method to bypassSecurityTrustResourceUrl

this.img = this.sanitization.bypassSecurityTrustResourceUrl('url(${this.user.profileImagePath})');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.