I have a real-time database on Firebase, and I want to retrieve records from this database using parameters.
For example, in the hierarchy you see, I want to get the data using the uID value. How can I do that?
UPDATE
https://javebratt.com/firebase-objects-ionic-2-app/
I have tried the heading "Read Firebase Data" in the article on the link I gave, but I do not know how to update the code if it is written for Ionic 2.
Here is the code I wrote,
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Post } from '../../models/models/post';
import { AngularFireDatabase } from 'angularfire2/database';
import { Storage } from '@ionic/storage';
@IonicPage()
@Component({
selector: 'page-profile',
templateUrl: 'profile.html',
})
export class ProfilePage {
public posts: Post[];
public uID: string;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private db: AngularFireDatabase,
private storage: Storage) {
this.storage.get('uID').then((val) => {
console.log('uID: ' + val);
this.uID = val;
console.log('this.uID: ' + this.uID);
this.db.list<Post>('/Post/',
ref => ref.orderByChild('uID').equalTo(this.uID)).valueChanges().subscribe(t => {
this.posts = t;
})
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad ProfilePage');
}
}
According to the article I had to do create a variable which is type of "Reference", but with AngularFireDatabase it is not possible to make such a definition.
How do I update this definition in Ionic 3?
UPDATE
I added some codes;
db.database.ref('/User/').on('value', res => {
console.log("Try Val: " + res.val)
console.log("Try Key: " + res.key)
console.log("Try Child: " + res.child)
});
And outputs;
Try Val: function () {
util_1.validateArgCount('DataSnapshot.val', 0, 0, arguments.length);
return this.node_.val();
}
Try Key: User
Try Child: function (childPathString) {
util_1.validateArgCount('DataSnapshot.child', 0, 1, arguments.length);
// Ensure the childPath is a string (can be a number)
childPathString = String(childPathString);
validation_1.validatePathString('DataSnapshot.child', 1, childPathString, false);
var childPath = new Path_1.Path(childPathString);
var childRef = this.ref_.child(childPath);
return new DataSnapshot(this.node_.getChild(childPath), childRef, PriorityIndex_1.PRIORITY_INDEX);
}
UPDATE
I could get data, but it's not clear answer.
Firebase records all data with a key value. I also added this key value after the "/ Post /" value as the data path. For example "/ Post / -1ersksnu0nsw1 /".
Here is the code;
db.database.ref('/User/-L88gtymS5pS3KWtZrmI').on('value', res => {
console.log(res.val().email)
});
And I could get true value, but I still do not know how to do this according to the columns of their records.