Listview没有使用Angular在混合移动应用程序中显示数据

问题描述 投票:0回答:1

我是角度应用程序离子的新手,我试图使用下面的代码显示listview但我得到例外如下所示可以有人建议我如何解决这个问题

'arrayList' is declared but its value is never read.
      L9:  export class HomePage {
      L10:    private arrayList:Array<any>=[];
      L11:    constructor(public navCtrl: NavController) { }

home.ts

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { DetailPage } from '../detail/detail';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  private arrayList:Array<any>=[];
  constructor(public navCtrl: NavController) {
   }

  ionViewDidLoad() {
    this.arrayList = [{name:"Ramakrishna1",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna2",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna3",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna4",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna5",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna6",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna7",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna8",email:"[email protected]",phoneNumber:"8008824731"},
    {name:"Ramakrishna9",email:"[email protected]",phoneNumber:"8008824731"}];
  }
}

home.html的

<ion-header>
  <ion-navbar color="primary">
    <ion-title>
      ListView
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
    <ion-list>
        <ion-item *ngFor="let list of arrayList" text-wrap>
            <h2>{{list.name}}</h2>
            <p>Email: {{list.email}}, Number: {{list.phoneNumber}}</p>
          <button ion-button clear item-right (click)="goToDetails(list)">View</button>
        </ion-item>
      </ion-list>
</ion-content>
angular ionic-framework
1个回答
0
投票

变量arrayList是私有的,因此您无法在--prod-mode中的模板中访问它。如果没有在模板中读取,它就被认为是未使用的。

把它变成

arrayList:Array<any>=[];

没有private。默认访问修饰符是公共的,您需要将其公开才能在模板中读取。

© www.soinside.com 2019 - 2024. All rights reserved.