简体   繁体   中英

Return data in ionic app

I linked the webservice with the app successfully and the data is retrieved but I can't access the data to display it or use it in any process.

 constructor(public navCtrl: NavController, public navParams: NavParams, public apiProvider: ApiProvider, public alertCtrl: AlertController) { this.usercheck = this.apiProvider.UserCheck(); this.usercheck.subscribe(data => {console.log('my data: ', data); }); 

The result retrieved by the console.log is:

在此处输入图片说明

and I am using this code to display the data in ionic element.

 <ion-list> <button ion-item *ngFor="let user of (usercheck|async)?.Array" (click)="openDetails(user)"> {{ user.CinemaName }} </button> </ion-list> 

but there is no result

thanks in advance.

You need to replace below code

constructor(public navCtrl: NavController, public navParams: NavParams, public apiProvider: ApiProvider, public alertCtrl: AlertController) {
    this.usercheck = this.apiProvider.UserCheck();
    this.usercheck.subscribe(data => {console.log('my data: ', data); });

to

testData: any = [];

constructor(public navCtrl: NavController, public navParams: NavParams, public apiProvider: ApiProvider, public alertCtrl: AlertController) {
        this.usercheck = this.apiProvider.UserCheck();
        this.usercheck.subscribe(data => this.testData = data;);

And replace below code

<ion-list>
    <button ion-item *ngFor="let user of (usercheck|async)?.Array" (click)="openDetails(user)">
      {{ user.CinemaName }}
    </button>

  </ion-list>

to

<ion-list>
    <button ion-item *ngFor="let user of testData" (click)="openDetails(user)">
      {{ user.CinemaName }}
    </button>

  </ion-list>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM