I need assistance with retrieving data from a firebase database and storing it in an array using typescript. Below is the code snippet I am working with:
export class ViewUserPage {
public list = [];
public ref = firebase.database().ref();
public usersRef = this.ref.child('users');
constructor(public navCtrl: NavController, public navParams: NavParams) {}
ionViewDidLoad(){
this.usersRef.orderByChild('tag').equalTo('staff').on('child_added',function(snap){
this.list.push(snap.val());console.log(snap.val());
});
}
}
The issue I'm encountering is that I keep getting this error message "Cannot read property 'list' of null". It seems to be happening within the
this.usersRef.orderByChild('tag').equalTo('staff').on('child_added',function(snap){
this.list.push(snap.val());console.log(snap.val());
part of the code. The complete error reads as follows:
ERROR TypeError: Cannot read property 'list' of null
at main.js:59030
at main.js:30999
at fc (main.js:30861)
at bf (main.js:30926)
at cf (main.js:30925)
at Qg.g.Gb (main.js:31016)
at Ag.g.wd (main.js:30980)
at og.wd (main.js:30970)
at Yf.Xf (main.js:30968)
at ag (main.js:30952)
defaultErrorLogger @ main.js:1436
Any suggestions on how to address this issue would be greatly appreciated! Thank you!