2017-02-02 59 views
0

在我的應用SL-Leg中有一個類,它有一些變量可以保存這些值。 當我打印這個類的對象,然後[對象對象]正在打印 但當我嘗試通過myObject.line訪問該類的值例如那麼有一個錯誤undefined不是一個對象(評估self.context。 $ implicit.line打印離子中的自定義對象2

略論法家是數組,其保持從類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-腿是這裏 我

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'); 
    } 
} 
+0

可以爲您添加HTML的元件側是否設置了legList? –

+0

我可以添加到現有的問題。我正在嘗試但不能看到選項。 有一個具有Leglist數組的類SL-Trip。Leglist數組中的腿正在填充 –

+0

您可以在問題 –

回答

0

陣列LegList中的第一個對象是nullundefined。 你可以只是把空校驗

{{leg?.line}}

另外,legIndex值從1 開始我想你用for循環開始索引插入1

+0

非常感謝。你是偉大的Suraj :) –