无法显示动态数组,离子2的值

时间:2017-05-22 07:44:00

标签: arrays dynamic ionic2

我已经像这样定义了数组

addressData: Array<
{
  title: any, city: any,country: any, 
  locality1: any,locality2: any,state: any, 
  street:any, zip_code:any,icon: any, 
  showDetails: boolean
}> = [];

现在我按这样推送数组的值

this.addressData.push
      ({
          title: 'Address',
           city:this.mapDetails.address[0].city,
           country:this.mapDetails.address[0].country,
           locality1:this.mapDetails.address[0].locality1,
           locality2:this.mapDetails.address[0].locality2,
           state:this.mapDetails.address[0].state,
           street:this.mapDetails.address[0].street,
           zip_code:this.mapDetails.address[0].zip_code,
          icon: 'ios-add-circle-outline',
          showDetails: false
        });

mapDetails - 包含数组对象,对象名为地址且索引为0,因此我使用“this.mapDetails.address [0]”来访问值。

在HTML中,我使用ngFOr迭代这样的值

<ion-item padding *ngFor="let d of addressData" (click)="toggleDetails(d)"><ion-icon color="primary" item-right [name]="d.icon"></ion-icon>
      {{d.title}}
      <div *ngIf="d.showDetails">
        {{d.street}}<br/>
        {{d.locality2}}<br/>
        {{d.city}} - {{d.zip_code}}<br/>
        {{d.state}} - {{d.country}}<br/>
      </div>
    </ion-item>

问题是,我得到的错误是

  

“ModalCmp ionViewPreLoad错误:无法读取未定义的属性'地址'”

请帮我解决这个错误。

0 个答案:

没有答案