0

I've added an Ion-select in my project, and I'm trying to filter for when I click, just show the information for that click. But for some reason it is giving me error and how I am new in all this, I do not know what it can be. If anyone can help me, I will be very happy. And I'm sorry for the translated English.

HTML

<ion-select (ionChange)="selecionaregiao()" [(ngModel)]="regiao">
    <ion-option value="opt1"></ion-option>
    <ion-option value="opt2">Zona Oeste</ion-option>
    <ion-option value="opt3">Zona Norte</ion-option>
    <ion-option value="opt4">Zona Sul</ion-option>

</ion-select>

DATABASE.TS

 getRegiao(pregiao: string){
return new Promise<Regiao[]>((resolve, reject) => { 

  let sql = "SELECT * FROM TB_REGIAO" + pregiao;
  console.log(sql);          
  this.executeQuery(sql).then(data => {
    let regioes = [];
    data.forEach(function (row) {
      let regiao: Regiao = { nom_regiao: row[0]}
      regioes.push(regiao);
    });
    resolve();

  }).catch(error => {
    console.log(error);
  });

});


}

and Function .ts

selecionaregiao(pregiao: string) {
this.db.getRegiao(pregiao)
        .then(data => this.regioes = data)
        .catch(error => console.log('Something want wrong!'));
}
Sabyasachi Patra
  • 650
  • 4
  • 12
Felipe XST
  • 141
  • 1
  • 14

1 Answers1

0

In your function ts you are defining the function with a parameter.

selecionaregiao(pregiao: string) {
this.db.getRegiao(pregiao)
        .then(data => this.regioes = data)
        .catch(error => console.log('Something want wrong!'));
}

But in the html you are not passing any argument.

So changing your ion-select might solve the issue

<ion-select (ionChange)="selecionaregiao(regiao)" [(ngModel)]="regiao">
    <ion-option value="opt1"></ion-option>
    <ion-option value="opt2">Zona Oeste</ion-option>
    <ion-option value="opt3">Zona Norte</ion-option>
    <ion-option value="opt4">Zona Sul</ion-option>

</ion-select>
Sabyasachi Patra
  • 650
  • 4
  • 12
  • I get the error: "ERROR Error: no such table: TB_REGIAOopt3 at Database.webpackJsonp.318.Database.handleError (sql.js:20) at Database.webpackJsonp.318.Database.exec (sql.js:20) at XMLHttpRequest.xhr.onload [as __zone_symbol__ON_PROPERTYload] (database.ts:114) at XMLHttpRequest.H (polyfills.js:3) at t.invokeTask (polyfills.js:3) at Object.onInvokeTask (core.js:4751) at t.invokeTask (polyfills.js:3) at r.runTask (polyfills.js:3) at e.invokeTask [as invoke] (polyfills.js:3) at p (polyfills.js:2)" – Felipe XST Aug 03 '18 at 20:29
  • In your database.ts, check if 'pregiao' is passed there properly. Also make sure "TB_REGIAO" + pregiao matches a table name. – Sabyasachi Patra Aug 03 '18 at 20:39
  • How do I check this? my database is as I posted in the question. I'm sorry I'm still learning, so I really should have something wrong with my database.ts, but I do not know how to find out – Felipe XST Aug 03 '18 at 20:47
  • Yes, using sqlite – Felipe XST Aug 04 '18 at 12:26
  • You can check this post, to check if a table exists, https://stackoverflow.com/questions/1601151/how-do-i-check-in-sqlite-whether-a-table-exists – Sabyasachi Patra Aug 04 '18 at 12:42
  • I could not with the post mentioned. I have not yet solved my problem, I am looking for a tutorial on how to do this, but I have not found anything yet. – Felipe XST Aug 06 '18 at 20:16