I am new to Angular. I am trying to change the layout of the my webpage based on whether a user is logged in or logged out. However this can be done only when the 'true' of 'false' is retrieved from the server. How can I do that? The TS code snippet is:
lgn: boolean;
ngOnInit(): void {
this.auth.onAuthStateChanged((user) => {
if (user) {
this.lgn = true;
} else {
this.lgn = false;
}
});
}
The HTML code snippet is:
<div *ngIf="lgn; then thenBlock; else elseBlock"></div>
<ng-template #thenBlock>Logged In</ng-template>
<ng-template #elseBlock>Not logged in</ng-template>
However this always shows 'Not logged in'.
onAuthStateChangedmethod pleaseonAuthStateChangedmethod is taken from@angular/firepackage. github.com/firebase/angularfire/blob/master/docs/…console.loginto your if else statement to check if it goes into it ? And alsoconsole.logyour user ?console.logshowstruewhen logged in andfalsewhen logged out. However the HTML file is rendered first before data is retrieved from the server. So it is a case where not logged in is displayed first and then the boolean value is retrieved. I want it to be the other way i.e., first data is received and then page is rendered.