i making a counter when everytime a users click a button it substracts 1 from the counter updates the node in firebase then return this change via another method with .valuechanges.subscribe but everytime this happens it refreshes the whole page deleting all user inputs.
constructor(private dd: PlayerInfoProvider, private strge: Storage, private ss: Slot2machineProvider, private slotProvider: SlotProvider) {
this.slotProvider.getTries(this.dd.getCurrentUser()).valueChanges().subscribe(snapshot => this.gettries(snapshot));
}
gettries(snapshot) {
// this.playerObject = snapshot;
this.tries = snapshot;
}
runSlots() {
if (this.tries <= 0) {
alert("you cannot play anymore sorry!! but if you want you can purchase some more luck");
} else {
this.slotOne = Math.floor(Math.random() * 52) + 1;
this.slotTwo = Math.floor(Math.random() * 52) + 1;
this.slotThree = Math.floor(Math.random() * 52) + 1;
this.slotFour = Math.floor(Math.random() * 52) + 1;
this.slotFive = Math.floor(Math.random() * 52) + 1;
// this.sloty1 = '<p > "' + this.slotOne + '"</p>';
// this.sloty2 = '<p > "' + this.slotTwo + '"</p>';
// this.sloty3 = '<p > "' + this.slotThree + '"</p>';
// this.sloty4 = '<p > "' + this.slotFour + '"</p>';
// this.sloty5 = '<p > "' + this.slotFive + '"</p>';
if (this.slotOne !== this.slotTwo || this.slotTwo !== this.slotThree) {
this.loggerr = "<h2>sorry try again.. </h2>";
this.playerObject.tries = this.tries - 1;
//alert("you only have " + this.playerObject.tries + " chances left ");
// this.ss.substractTries(this.dd.getCurrentUser(), this.playerObject);
} else {
this.loggerr = "<p>jackpot!!!</p>";
}
}
}