In the constructor of an Angular service, I am creating an observable to which I need to subscribe directly (no inner subscription). How to do it? In particular, in the first block of code below I have the variable data.id.
this.current_trainee = this.db.collection('Users', ref => ref.where(
'email', '==', 'EXAMPLE' )).snapshotChanges().pipe(
map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Trainee;
data.id = a.payload.doc.id;
return data;
});
})
);
Now I want to subscribe to it directly to use it in doc(data.id)" below:
this.trainees = this.db.collection('Users').doc( data.id ).collection('Trainings_taken').snapshotChanges().pipe(
map(changes => {
return changes.map(a => {
const data = a.payload.doc.data() as Trainee;
data.id = a.payload.doc.id;
return data;
});
})
);
I tried to subscribe to it in the following way:
this.current_trainee.subscribe(data => this.user_doc_id = data.id );
where user_doc_id
is initiated as an empty string. But it does not work because user_doc_id
stays an empty string. Any suggestion please? Thx in advance!