Ionic - erro (undefined) nome da Area

1 resposta
sqliteionic
M

Boa noite
Toda vez que executa essa linha this.toast.create({message: Você errou, a area correta é ${this.processo.NOME_AREA},duration: 3000,position: ‘top’}).present();. O valor da área está aparecendo como undefined

1 Resposta

M

Meu component :

@IonicPage()

@Component({

selector: page-area,

templateUrl: area.html,

})

export class AreaPage {
public codigoAreaEscolhida:number;

public acertos:number;

public tentativas:number;

//no android
public areas:any[];

//no computador
/*
public areas = [
{
NOME: “AREA 1”,
CODIGO_AREA: 1
},

{
  NOME: "AREA 2",
  CODIGO_AREA: 2
},

{
  NOME: "AREA 3",
  CODIGO_AREA: 3
}

];
*/

//no android

public processo = {

NOME:"",

CODIGO_PROCESSO:"",

CODIGO_AREA:0,

NOME_AREA:""

};
//no computador

/*

public processo = {

NOME: PROCESSO DE TRANSIÇÃO E TÉRMINO DE COMPONENTES PARA O TCC,

CODIGO_PROCESSO: 1,

CODIGO_AREA: 2,

NOME_AREA:INCIAÇÃO};

*/

constructor(public navCtrl: NavController, private toast: ToastController, private areaProvider: AreaProvider, private calculosProvider: CalculosProvider, private processoProvider: ProcessoProvider) {

this.acertos = 0;
this.tentativas = 0;
this.refresh();

}

refresh() {

// no android
this.getAreas();
this.getProcessoAleatorio();

}

getAreas() {

this.areaProvider.getAll()

.then((result: any[]) => {

this.areas = result;

<a href="//this.toast.create">//this.toast.create</a>({ message: “Areas carregadas com sucesso.”, duration: 1000, position: ‘botton’ }).present();

})

.catch(() => {

<a href="//this.toast.create">//this.toast.create</a>({ message: ‘Erro ao carregar as areas.’, duration: 1000, position: ‘botton’ }).present();

});

}

getProcessoAleatorio() {
let processoAleatorio = this.calculosProvider.getRandomInt(1, 48);

this.processoProvider.getById(processoAleatorio)
  .then((result: any) => {
    this.processo.NOME = result.NOME;
    this.processo.CODIGO_PROCESSO = processoAleatorio;
    this.processo.CODIGO_AREA = result.CODIGO_AREA;
    this.processo.NOME_AREA = result.NOME_AREA;
    this.toast.create({ message: "SUCESSO", duration: 1000, position: 'botton' }).present();
  })

}

enviar() {

if (this.processo.CODIGO_AREA == this.codigoAreaEscolhida) {

  this.toast.create({message: 'Parabéns, você acertou',duration: 3000,position: 'top'}).present();
  this.acertos++;

} else {
  this.toast.create({message: `Você errou, a area correta é ${this.processo.NOME_AREA}`,duration: 3000,position: 'top'}).present();
}
this.tentativas++;
this.refresh();

}

areaEscolhida(codigoArea:number){

this.codigoAreaEscolhida = codigoArea;

console.log(this.codigoAreaEscolhida);

}

}

Criado 25 de maio de 2018
Ultima resposta 25 de mai. de 2018
Respostas 1
Participantes 1