I am working on a project with angular2/firebase and using angularfire2 module. I want some realtime data so I use angularfire2 list and on component side using subscribe over the list. In real-time scenario, if any new item added in firebase database it subscribe but without any query. How I can archive subscribe with query? I am using following code where the query is some selection on which basis I want data.
getRealtimeData(query: any){
if(query){
return this.af.database.list(databaseName+"/messages", {
query: {
orderByChild: 'is_broadcast',
equalTo: query.value
}
});
} else {
return this.af.database.list(databaseName+"/messages", {
query: {
orderByChild: 'timestamp'
}
});
}
}
I am calling this in my component creating a query
var query;
if (this.isBroadcastMessage && this.isGroupChatMessage || !this.isBroadcastMessage && !this.isGroupChatMessage) {
query = null;
} else if (this.isBroadcastMessage && !this.isGroupChatMessage) {
query = {
value: true
};
} else if (!this.isBroadcastMessage && this.isGroupChatMessage) {
query = {
value: false
};
}
this.firebaseService.getRealtimeData(query).subscribe((data: any) => {
console.log("data::", data);
}, (error: any) => {
console.log("error::", error);
})
getRealtimeDatamethod? and also some logs of the object you receive?