- {{ balance | currency : 'EUR' : 'symbol' : '1.2-2' }}
+
+ Balance: {{ balance() | currency: 'EUR' : 'symbol' : '1.2-2' }}
@if (!isLoggedIn) {
diff --git a/frontend/src/app/shared/components/navbar/navbar.component.ts b/frontend/src/app/shared/components/navbar/navbar.component.ts
index 9365d41..a6bbc15 100644
--- a/frontend/src/app/shared/components/navbar/navbar.component.ts
+++ b/frontend/src/app/shared/components/navbar/navbar.component.ts
@@ -1,10 +1,9 @@
-import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
+import { ChangeDetectionStrategy, Component, inject, OnInit, signal } from '@angular/core';
import { RouterModule } from '@angular/router';
import { KeycloakService } from 'keycloak-angular';
import { UserService } from '../../../service/user.service';
-import { firstValueFrom } from 'rxjs';
-import { CurrencyPipe } from '@angular/common';
+import { CurrencyPipe } from '@angular/common';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
@@ -12,21 +11,22 @@ import { CurrencyPipe } from '@angular/common';
imports: [RouterModule, CurrencyPipe],
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class NavbarComponent {
+export class NavbarComponent implements OnInit {
isMenuOpen = false;
private keycloakService: KeycloakService = inject(KeycloakService);
isLoggedIn = this.keycloakService.isLoggedIn();
+
private userService = inject(UserService);
private user = this.userService.getCurrentUser();
- balance = 0;
+ public balance = signal(0);
- async ngOnInit() {
- const user = await firstValueFrom(this.user);
- this.balance = user?.balance ?? 0;
+ ngOnInit() {
+ this.user.subscribe((user) => {
+ this.balance.set(user?.balance ?? 0);
+ });
}
-
login() {
try {
const baseUrl = window.location.origin;