Reputation: 1115
I am ng-repeating the objects stored in my $firebaseArray
object.
mycontroller
:
var projectquery = DatabaseRef.ref("projects").orderByKey().equalTo("-KUTPrs6ARZXjbjtNr7O");
$scope.projectslist = $firebaseArray(projectquery);
html view with ng-repeat
:
<tr ng-repeat="obj in projectslist">
<td>{{ obj.field1}}</td>
<td>{{ obj.field2 }}</td>
<td>{{ obj.field3 }}</td>
<td>{{ obj.field4 }}</td>
</tr>
this is displaying only one project because I am passing in the project key manually to equalTo and thus filtering to show one.
From the other hand, I am getting a set of project keys from the below function by doing a forEach on another database where I get my project keys:
var keyquery = DatabaseRef.ref('/users/' + userId).orderByKey().once("value")
.then(function onSuccess(snapshot) {
snapshot.child("savedprojects").forEach(function(childSnapshot) {
var userprojects = childSnapshot.val();
console.log("my list is :", userprojects );
});
});
the output of the console is like:
my list is : -KUTLAZENGlxtzCtEfaZ
my list is : -KUTLM8r_kmVSTaxzLW5
my list is : -KUTPrs6ARZXjbjtNr7O
how is it possible to pass on the above list of project keys obtained from forEach into the first function which shows the projects and filters them by key?
Could somebody please give a relevant answer and help me solve this, without referring to other answers which are not directly related to my question?
thanks in advance!
my DatabaseRef refers to this factory, which is initializing the firebase database:
app.factory("DatabaseRef", function() {
return firebase.database();
});
After implementing Gourav's answer, my console shows undefined in place of the project IDs:
as you can see, the user has six projects under his profile, but all of them are empty and undefined.
here is console output after Gourav's edit:
Upvotes: 2
Views: 742
Reputation: 2911
I don't know much about DatabaseRef but this might help.
$scope.projectslist = [];
DatabaseRef.ref('/users/' + userId).orderByKey().once("value")
.then(function onSuccess(snapshot) {
snapshot.child("savedprojects").forEach(function (childSnapshot) {
var userprojects = childSnapshot.val();
console.log("my list is :", userprojects);
var projectquery = DatabaseRef.ref("projects").orderByKey().equalTo(userprojects);
$scope.projectslist.push(($firebaseArray(projectquery))[0]);
});
});
Upvotes: 5