Hey guys,
currently i’m working on a Ionic 2 app which receives data from a firebase database.
In my home.ts i recieve the data by
public events: any[] = [];
private userId: any;
constructor(public navCtrl: NavController,private app: App, public angfire: AngularFire, private auth: AuthProvider, private _event: Eventdata) {
this.userId = firebase.auth().currentUser.uid;
//get list of posts on page init
this.listEvents();
}
listEvents(){
var that = this;
this._event.listEventsService().then(snapshot => {
that.events.length = 0;
snapshot.forEach(function (childSnapshot) {
var data = childSnapshot.val();
data['key'] = childSnapshot.key;
that.events.push(data);
});
});
}
this data is provided by my Eventdata Provider
constructor() {
this._db = firebase.database().ref('/'); // Get a firebase reference to the root
this.userNode = firebase.database().ref('users');
this.eventsNode = firebase.database().ref('Events');
this.eventsUserNode = firebase.database().ref('user-events');
listEventsService(){
return this.eventsNode.once('value');
}
atm everythink works fine.
For the next step i tried to add a child_added and values listener to update my listview.
With
this.eventsNode.on("value", function(snapshot){
console.log("child added");
});
the “child_added” is called but i dont know how to receive the new data in my home.ts page and update the existing listview.
Would be nice if someone could explain me how it works