What angular version are you using?
Have you checked, if user is really written?
Here would be some changes I would try without further context:
Set changeDetection
@Component({
selector: 'app-header',
standalone: true,
imports: [RouterModule, NgIf],
templateUrl: './header.component.html',
styleUrl: './header.component.css',
changeDetection: ChangeDetectionStrategy.OnPush, //Add changeDetection
})
Use @if
instead of *ngIf
since it's deprecated with angular 20.
@if (user()) {
<span>Olá, {{ user().name }}</span>
} @else {
<button class="button" routerLink="/login">Entrar</button>
}