Take into account the following Angular
service:
@Injectable()
export class AuthService {
public userConnected: UserManageInfo;
getManageInfo(): Observable<UserManageInfo> {
return this.httpClient
.get('api/Account/ManageInfo', { headers: this.getCustomHeaders() })
.catch((error: Response) => {
if (error.status == 401)
return this.logout();
return Observable.throw(error)
})
.map((response: any) => {
this.userConnected = response;
return this.userConnected;
});
}
}
The method getManageInfo()
is called from the file app.component.ts
.
Moreover, upon application startup, the constructor of another component named AppSidebarComponent
should retrieve this information.
Currently, I am handling it in the following manner:
export class AppSidebarComponent implements OnInit {
public currentUser: UserManageInfo = new UserManageInfo();
constructor(private authService: AuthService) {
this.currentUser = this.authService.userConnected;
}
}
However, when the property changes, the currentUser
attribute within the AppSidebarComponent
does not reflect the update.
What would be an effective way to address this issue?