Home > Software engineering >  How to remove repeated link from main url in angular?
How to remove repeated link from main url in angular?

Time:03-10

I have created function to returm url for image src.

.ts file

get image() {    
    return `${environment.IMAGE_URL}profile_pic/`    this.user?.data?.image || `${environment.IMAGE_URL}profile_pic/`   "assets/images/user-chat.png";
}

.html file

<img [src]="image" height="50" width="50"">

Here, ${environment.IMAGE_URL}, I set static url for an example www.testwebsite.com.

But here problem is that in same this.user?.data?.image is coming from api side. Sometime value is coming only with image name and and some time coming with url and image name. So at that time my url got two time ${environment.IMAGE_URL}.

So I need to check that In my link is not repeat same text as shown as below image.

enter image description here

So How can I remove repeated link from main url in angular?

CodePudding user response:

Try this way

get image() {    
    return `${environment.IMAGE_URL}profile_pic/`    (this.user?.data?.image || "assets/images/user-chat.png");
}

CodePudding user response:

you should take out the first${environment.IMAGE_URL} as that will always be return. I would do something like this:

get image() {
    return (
      `${this.user?.data?.image}profile_pic/` ||
      `${environment.IMAGE_URL}profile_pic/`   "assets/images/user-chat.png"
    )
 }
  • Related