akveo / ngx-admin

Customizable admin dashboard template based on Angular 10+
https://akveo.github.io/ngx-admin/
MIT License
25.21k stars 7.95k forks source link

Header component nb-user doesn't update user name #5573

Open abwaters opened 4 years ago

abwaters commented 4 years ago

Issue type

I'm submitting a ... (check one with "x")

Issue description

Current behavior:

I have a service that allows a user to login and logout and I'm updating the [name] input on the nb-user component in the header (header.component.ts). I logout and log back in as another user and update the user information in the header when this happens.

The change is not detected and i'm not sure how to do this correctly or if this is a defect.

Expected behavior:

I would update the value that is bound to the nb-user component name attribute and the component would update accordingly.

Steps to reproduce:

Bind a value to the name attribute and change it later.

Related code:

// header.component.ts snippet // inserted into ngOnInit this.authService.getUser().subscribe(user => { this.userName = user.attributes.name; console.log(User logged in: ${this.userName}); });

// header.component.html snippet <nb-action class="user-action" *nbIsGranted="['view', 'user']" > <nb-user [nbContextMenu]="userMenu" nbContextMenuTag="user-menu" [onlyPicture]="userPictureOnly" [name]="userName">

Other information:

npm, node, OS, Browser

<!--
Node, npm: node v10.15.0, npm 6.13.1
OS: windows 10
Browser: Chrome 78.0.3904.108
-->

Angular, Nebular

<!--
Angular 8.0.2
Nebular 4.4.0
-->
Prefix1802 commented 4 years ago

My code. My server puts user name in user?.Identity, but you can model the DTO any way you want.

// header.component.ts snippet // inserted into ngOnInit this.auth.getUser() .subscribe((data: any) => { console.log(data); this.user = data; });

// header.component.html snippet <nb-user [nbContextMenu]="userMenu" [onlyPicture]="userPictureOnly" [name]="user?.Identity" [picture]="'data:image/jpeg;base64,'+user?.Avatar">

pellyadolfo commented 4 years ago

same here.

  <nb-user [nbContextMenu]="userMenu"
           [onlyPicture]="userPictureOnly"
           [name]="username"
           [picture]="user?.picture">
  </nb-user>
  username: string;
....
  ngOnInit() {
....
    this.storageService.changes
      .subscribe((changes: any) => {
....
    this.username = user.id.userid;
    console.log(this.username);
....
      });

The log shows the username properly. However it does not show into the component.

If I set it explicitly the value: username: string = 'myname'; this works

alokraj68 commented 4 years ago

Any update on this issue?