[IONIC] Bug sur affichage d'un tableau

Par JESSYV96, il y a 7 ans


Bonjour,

je débute en Ionic, j'ai un problème sur mon projet, j'affiche une question au hasard depuis un tableau a chaque changement d'ecrans, mais lorsque mon tableau est vide, il continue à essayer d'afficher une question.

displayOneQuestion() { let questionRandom: any = this.questionList; let numRandom = Math.floor(Math.random() * this.questionList.length); this.currentQuestion = this.questionList[numRandom]; questionRandom = this.questionList[numRandom].getTitle(); return questionRandom; } setQuestionList() { let questionList = this.questionList; let questionListIndex = this.questionList.indexOf(this.currentQuestion); let questionListSpliced = questionList.splice(questionListIndex , 1); console.log(questionListSpliced); } ionViewWillEnter() { this.question = this.displayOneQuestion(); this.displayLife(); this.displayJoker(); }

J'aimerai pouvoir stopper l'affichage des questions si mon tableau est vide

sa donne une erreur : Cannot read the propery getTitle() on undefined

Si besoin, demandez moi plus de precision cest la premiere fois que je poste sur un forum lol

2 réponses

Defy, il y a 7 ans

ben une simple condition devrait regler le probleme. si tonTableau.lenght > 0 je lance ma fonction sinon je fait rien

JESSYV96, il y a 7 ans

Ah merci beaucoup, ça fonctionne.