Trying to extract data from a WEB API service using Angular 8 has been quite challenging for me.
A service I created makes the API call:
return this.http.get<UserSession>(uri)
.pipe(map((json: UserSession) => this.EntryFormAdapter(json)));
This service then utilizes a data adapter to convert the JSON, although I'm unsure if it's necessary due to strong typing. Interestingly, adding properties to the UserSession constructor causes it to malfunction.
UserSession (fully functional):
export class UserSession {
public SessionId: string;
public SessionTimeout: number;
public User: User;
}
UserSession (not functioning correctly):
export class UserSession {
constructor (public SessionId: string,
public SessionTimeout: number,
public User: User) { }
}
I need to keep the UserSession in global data so that the SessionId is accessible for my HMAC HttpInterceptor.
Interceptor (partially implemented):
constructor(private userSession: Observable<UserSession>) {
this.userSession.subscribe(us => this.sessionId = us.SessionId);
}
I've dedicated countless hours trying to resolve these two key issues: 1) Making a parameterized constructor function properly 2) Storing a global UserSession object for use in other modules.