HaithemMosbahi/ngx-avatar

Avatar is not updated if src is removed dynamically

andbjer opened this issue · 9 comments

In a project I am working on, I want to users to be able to choose their own image as avatar, and use the "initials avatar" if they don't have an image. I also want them to be able to remove an image.

When removing the image, src is updated to null. This does not update the avatar, and the image is still showing.

I have made a StackBlitz demo demonstrating my issue.

I use the following workaround right now, but I think this is something the component should be able to handle internally:

<ngx-avatar *ngIf="src; else initialsAvatar" [src]="src" [name]="name" [size]="size"></ngx-avatar>

<ng-template #initialsAvatar>
  <ngx-avatar [name]="name" [size]="size"></ngx-avatar>
</ng-template>

+1
If I will change the user dynamically, avatar still show 'old' photo

I can confirm this is a bug.
You forget to bind the name property in your StackBlitz example btw.

+1

Same here.

bind src={{object.src}} doesn't change the image when has a new model

any solutions for this ??

Same issue here, this question was asked almost a year ago, not sure that's gonna be fixed someday.

I'm not sure but maybe the current master branch already fixes this. We just don't have a publish date for it. We should test to see if it fixes the issue, otherwise make this a feature request.

Sounds good. I set a wrong string to src when I want to hide it, but that's not clean though, just a work around

I am facing the same issue now, but assign random string worked for me