在离子2中打印自定义对象

时间:2017-02-02 13:22:00

标签: ionic2

我的应用程序SL-Leg中有一个类。它有一些可以保存值的变量。 当我打印该类的对象时,则打印[对象对象] 但是当我尝试通过myObject.line访问类的值时,例如然后有一个错误undefined不是一个对象(评估self.context。$ implicit.line

leglist是一个数组,用于保存SL'Leg类中的对象。

<ion-header>

  <ion-navbar>
    <ion-title>showTripInfo</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
<ion-content class="show-trips">
    <ion-list>
      <ion-item-group *ngFor="let leg of legList" (click) = "showTripInfo(tp)">
        <ion-card>

          <table style="width:100%">
<tr>
  <div class="page-show-trips.card-title">

    <th item-width="100%">{{leg}} >> {{leg.line}}</th>
  </div>
</tr>
<tr>
  <div class="page-show-trips.card-subtitle">
    <th item-width="100%">{{leg}} >> {{leg}}</th>
  </div>
</tr>
</table>



<div ng-repeat="(key, value) in tp.LegList" > {{key}} {{value}} </div>

</ion-card>

</ion-item-group>
</ion-list>
</ion-content>
</ion-content>

SL-Leg在这里 我

mport { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Address } from './sl-Address';

/*
  Generated class for the SlTripClass page.
  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-sl-legs',
  //templateUrl: 'sl-trip-class.html'
})
export class Leg {
    // public from_time: String;
    public legIndex: Number;
    public enabled_TransportType: Boolean; // Default True
    public enabled_LineNumber: Boolean; // Default true
    public showHideLeg: Boolean; // Default true means show all legs
    public filterLine: Boolean;
    public filterDepartures: Boolean;
    // ...:Common publiciables available in Travel /Walk
    public journeyType : String;
// available via LegDetail
    public origin: Address;
    public destination: Address;
    public name: String;
    public type: String;
    public idx: String;
    public geomRef: String;
    public legImageName: String;
    //-- Only found in --------Walk
    public dist: String;
    public hide: String;
    //-- Only found in --------Travel
    public dir: String;
    public line: String;
    public journeyDetailRef: String;
    public rtu_Message_Flag: Boolean;
    public rtu_Message: String;
//  constructor(public tripObjectFromSl: any,public navCtrl: NavController, public navParams: NavParams) {
    constructor() {
    this.legIndex = 0;
    this.enabled_TransportType= true; // Default True
    this.enabled_LineNumber= true;
    this.showHideLeg= true;
    this.filterLine= false;
    this.filterDepartures;
    this.journeyType= String();;
    this.origin= new Address();
    this.destination= new Address();
    this.name= String();
    this.type= String();
    this.idx= String();
    this.geomRef= String();
    this.legImageName= String();
    this.dist= String();
    this.hide= String();
    //-- Only found in --------Travel
    this.dir= String();
    this.line= String();
    this.journeyDetailRef= String();
    this.rtu_Message_Flag= true;
    this.rtu_Message= String();
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad SlTripClassPage');
  }
}

1 个答案:

答案 0 :(得分:0)

数组tr '[:space:]' ' ' < program.c > unreadable.c 中的第一个对象是LegListnull。 你可以放一个空检查

undefined

{{leg?.line}}值也从1开始。 我想你用for循环索引1插入。