Currently, I am facing a peculiar issue where I retrieve the user's profile from Firebase
, and within this profile lies a Photo Object containing an array of photos uploaded by the user.
This is my getUserProfile method:
getUserProfile(): Observable<User> {
var userId = null;
var auth = this.af.auth.subscribe(user => {
userId = user.uid;
});
auth.unsubscribe();
return this.af.database.object('/users/' + userId)
.map(pro => new User(
pro.$key,
pro['email'],
pro['gender'],
pro['last_name'],
pro['first_name'],
pro['display_name'],
pro['photos'],
pro['hobbies']))
}
The structure of my User class is as follows:
export class User {
public constructor(
public userId: string,
public email: string,
public gender?: string,
public last_name?: string,
public first_name?: string,
public display_name?: string,
public photos: Photo[] = [],
public hobbies: Hobbies[] = [],
) { }
}
In my component, I invoke the getUserProfile method like this:
this.userSubscription = this.profileService.getUserProfile().subscribe(profile => {
console.log(profile.photo);
});
Despite logging console.log(profile.photos);
, when attempting to loop through the collection with:
for(var i = 0; i < profile.photos.length; i++){
console.log('here');
}
No output is displayed in the console. Even trying
console.log(profile.photos.length);
results in 'undefined'.....
I am not entirely certain what could be causing this issue. Can anyone identify why looping through the photo array and accessing its properties seems to be failing?