Here is an example of the ProfileService I am currently using:
export class ProfileService {
private user: BehaviorSubject<User> = new BehaviorSubject<User>(null);
constructor(private userService: UserService) {
this.userService.getUser(1)
.pipe(map((payload: Payload<Result>) => payload.result))
.subscribe((User: user): this.user.next(user));
}
public getUser() : Observable<User> {
return this.user.asObservable();
}
}
In some components, I inject the AuthorizationService
and utilize the authorize
method:
export class AuthorizationService {
user$: Observable<User>;
constructor(private profileService: ProfileService) {
this.user$ = this.profileService.getUser();
}
authorize(policy: Policy, data: any) : Observable<boolean> {
this.user$.subscribe(x => console.log(x)); // ISSUE ARISES HERE
// Remaining code
}
}
Challenge
Every time I include console.log
in the authorize
function, the value of user$
seems to be null initially.
Do you have any insights on why this might be happening?