-3

How do I display a photo of an authorized user? Tried to do so:

  <div *ngIf="authTokenService.currentUserData">
    <img class="img" src="assets/img/empty_photo.png" [(ngModel)]="authTokenService.currentUserData.user_photo" name="user_photo">
  </div>

but gives an error:

ERROR Error: No value accessor for form control with name: 'user_photo'

Kamil Naja
  • 6,267
  • 6
  • 33
  • 47
Nonsense
  • 250
  • 2
  • 7
  • 15

1 Answers1

2

You don't have to use NgModels because their only used in forms or inputs; you can just simply change the source (attr src) to the users img url like this:

<div *ngIf="authTokenService.currentUserData">
    <img class="img" [src]="authTokenService.currentUserData ? authTokenService.currentUserData.user_photo : 'assets/img/empty_photo.png'" name="user_photo">
</div>

and btw this *ngIf for the container element is pretty useless in this case because it cannot even reach the empty image if there's no user

Tobias Fuchs
  • 910
  • 5
  • 8