I have the following code:
//Loop: For each user ID/Role ID, get the data
userMeta.forEach((businessRole) => {
Observable.forkJoin(
af.database.object('/roles/'+businessRole.$value),
af.database.object('/users/'+businessRole.$key)
).subscribe(
data => {
console.log("Data received");
data[1].role = data[0];
this.users.push(data[1]);
},
err => console.error(err)
);
I am trying to subscribe to a result of 2 observables using forkJoin
.
For some reasons, the "Data received" message is not shown.
My userMeta
variables looks fine at console.log:
What's wrong?
Update: the following code does not return anything either
let source = Observable.forkJoin(
af.database.object('/roles/'+businessRole.$value),
af.database.object('/users/'+businessRole.$key)
);
let subscription = source.subscribe(
function (x) {
console.log("GOT: " + x);
},
function (err) {
console.log('Error: %s', err);
},
function () {
console.log('Completed');
});
What I actually trying to do is improve the performance of the following code:
//Subscription 3: role ID to role Name
af.database.object('/roles/'+businessRole.$value)
.subscribe((roleData) => {
//Subscription 4: Get user info
af.database.object('/users/'+businessRole.$key).subscribe(user => {
forkJoin()
emits a value after both Observables complete, so are you sure they do? Maybe one of them end with an error... – KrauseforkJoin()
doesn't pass errors from source Observables so this won't print anything even if it threw errors. If you want to make sure it doesn't emit errors you need to subscribe to each of the source Observables. – Krause