0

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>";
      }
    }
  }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user3640924
  • 27
  • 1
  • 4
  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve)" – Frank van Puffelen Dec 02 '18 at 19:10
  • ok thank you very much – user3640924 Dec 10 '18 at 20:01

0 Answers0