Ionic2 在ionic 2中打印自定义对象

Ionic2 在ionic 2中打印自定义对象,ionic2,Ionic2,我的应用程序SL-Leg中有一个类。它有一些变量可以保存这些值。 当我打印这个类的对象时,就会打印[object] 但是,当我尝试通过myObject.line访问类的值时,例如,出现了一个错误,未定义的不是对象(计算self.context.$implicit.line) leglist是一个数组,它保存来自类SL'Leg的对象 <ion-header> <ion-navbar> <ion-title>showTripInfo</ion-

我的应用程序SL-Leg中有一个类。它有一些变量可以保存这些值。 当我打印这个类的对象时,就会打印[object] 但是,当我尝试通过myObject.line访问类的值时,例如,出现了一个错误,未定义的不是对象(计算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>

数组
LegList
中的第一个对象是
null
undefined
。 你可以把一个空的检查

{{leg?.line}}

此外,
legIndex
值从1开始。
我想您正在使用for循环起始索引1进行插入。

可以添加html的组件端吗?如果设置了legList,我可以添加到现有问题中吗?我正在尝试,但看不到选项。有一个具有legList数组的SL Trip类。在legList数组中,腿正在填充,您可以在打印对象时使用问题
中的编辑选项你没有得到[object object]
你是在谈论控制台日志吗?不是在控制台上,它经常从HTMLTanks打印在视图上。你真是太棒了Suraj:)
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');
  }
}