samedi 30 juin 2018

Ionic 3 - all if are activated at the same time (JS)

I have a little problem and i can't find the solution,

i have this little fonction here:

Clicked(){
       for (let i = 0; i < 5; i++) {
          if (this.ShareProvider.ValueFonction(i)) {
            alert(i)
          }
        }
}

There 6 buttons and what i'm trying to do is when I click a button the alert() fonction will launch. The problem is that when I run the program, it shows the 6 alerts in a row. I tried to write different way but same issue.

if (this.ShareProvider.ValueFonction(1)) {
  alert(1)
}
if (this.ShareProvider.ValueFonction(2)) {
  alert(2)
}
if (this.ShareProvider.ValueFonction(3)) {
  alert(3)
}
if (this.ShareProvider.ValueFonction(4)) {
  alert(4)
}
if (this.ShareProvider.ValueFonction(5)) {
  alert(5)
}
if (this.ShareProvider.ValueFonction(6)) {
  alert(6)
}

or

if (this.ShareProvider.ValueFonction(1)) {
  alert(1)
}
if (this.ShareProvider.ValueFonction(2)) {
  alert(2)
}
if (this.ShareProvider.ValueFonction(3)) {
  alert(3)
}
if (this.ShareProvider.ValueFonction(4)) {
  alert(4)
}
if (this.ShareProvider.ValueFonction(5)) {
  alert(5)
}
if (this.ShareProvider.ValueFonction(6)) {
  alert(6)
}

Thanks for you attention

Aucun commentaire:

Enregistrer un commentaire