使用数据库数据制作选择列表 - Ionic 3

时间:2017-07-18 19:00:01

标签: ionic-framework ionic2 ionic3

我在使用数据库中的数据制作选择列表时遇到问题。 我遵循了一些互联网教程,但无济于事。 如果有人可以发布一个例子或指出我错了。 我将非常感激,因此,我必须在加载第3页选择列表时这样做。

auth_pagto.ts

empresa(user) {
    //user.sidBanco = "bda1";
    var headers = new Headers();
    headers.append('Content-Type', 'application/json; charset=utf-8');

    return new Promise(resolve => {
        this.http.post('/itpowerbr-api/login/empresa', JSON.stringify(user), {headers: headers}).subscribe(data => {
              console.log("ENTROU");

              var mostraEmpresa: any[];
              //lista das empresas
              data.json().each(data, function(i, x){
                  //mostraEmpresa += '<ion-option value="'+ x.empresaNome +'" >'+ x.empresaID +' - '+ x.empresaNome +'</ion-option>';
                  //{description: "Fazer compras", priority: "7", horary: "22:20"},
                  this.mostraEmpresa = [
                    {description: x.empresaNome, priority: x.empresaID}
                  ];
              });
              //$("#pgt-lista-filial").html(mostraEmpresa);
              resolve(mostraEmpresa);
        }, (err) => {
          if ( err.status == 500 ){
            var alert = this.alertCtrl.create({
                      title: "Pagamentos",
                      subTitle: "Lista Empresa não Encontrada",
                      buttons: ['ok']
                  });
            alert.present();
            resolve(false);
          }else{
            var alert = this.alertCtrl.create({
                      title: "Pagamentos",
                      subTitle: err,
                      buttons: ['ok']
                  });
            alert.present();
            resolve(false);
          }
        });


    });



}// fim

pagamento.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController, LoadingController } from 'ionic-angular';
import { Auth_Pgto } from './auth_pgto';
import { AuthService } from '../login/authservice';
import { Storage } from '@ionic/storage';

import { LoginPage } from '../login/login';

@IonicPage()
@Component({
  selector: 'page-pagamentos',
  templateUrl: 'pagamentos.html',
})
export class PagamentosPage {

  usercreds = {
      //nomeUsuario: '',
      //token: ''
   };

private _lista: any;

constructor(public navCtrl: NavController, public storage: Storage, public navParams: NavParams, public authservice: AuthService, public auth_pgto: Auth_Pgto, public alertCtrl: AlertController, public loadingCtrl: LoadingController) {
  var usuario = new Object();
  usuario = {
    nomeUsuario: window.localStorage.getItem('usuario'),
    token: window.localStorage.getItem('raja')
  };

  this.auth_pgto.empresa(usuario).then(data => {
    this._lista = data;
  });

  }// fim

  logout() {
        this.authservice.logout();
        this.navCtrl.setRoot(LoginPage);
  }

  public event = {
    month: '2017-07-01',
    timeStarts: '07:43',
    timeEnds: '1990-02-20'
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad PagamentosPage');
  }

}

pagamentos.html

<ion-content padding>
  <ion-list> <!-- LISTA EMPRESA -->
    <ion-item *ngFor="#_lista of _lista">
    <ion-label>Empresa</ion-label>
     {{lista.description}}
    </ion-item>
  </ion-list>
</ion-content>

非常感谢你。

1 个答案:

答案 0 :(得分:0)

我认为您错过了let指令中的ngFor关键字。

<ion-item *ngFor="let item of _lista">