Hi All,
I created a provider page and a user navigation page. The provider’s data gets updated when multiple users add/modify scores from the navigation page. But USER1’s page doesn’t get updated automatically unless I close and re-enter into the page when USER2 entered a new score or modified an existing score. Or even if USER1 modified the score when he is on the same page. How can I trigger changes to the navigation page when the data in the provider changes? Hows does navigation page know that the provider data has changes when we are already on the same page?
Here is my provider code (scoreProvider.ts)
getScores(): firebase.Promise<any> {
return firebase.database()
.ref('/scores')
.orderByChild('startDate')
.on('value', snapshot => {
let rawList = [];
snapshot.forEach(snap => {
rawList.push({
season: snap.key,
startdate: snap.val().startDate,
enddate: snap.val().endDate,
winner: snap.val().winner,
runner: snap.val().runner,
});
return false
});
resolve(rawList);
});
}
Here is my user’s navigation page code (scores.ts)
ionViewDidLoad() {
this.scoreProvider.getScores.then(snapshot => {
this.scores = snapshot;
});
}
If I move the entire code for getScores from the scoreProvider.ts to scores.ts, the page’s data gets updated automatically without refreshing the page. But,what if I need scores to be available on multiple pages. I have to duplicate the entire code everywhere which I am trying to avoid.
