我有一個CheckIn
頁面,它具有title
屬性。在Ionic 2中,如何在兩個組件之間傳遞屬性數據?
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
templateUrl: 'check-in.html'
})
export class CheckInPage {
public title: string = 'Check In';
constructor(public navCtrl: NavController) {
}
}
我在TabsPage
導入這個頁面:
import { Component } from '@angular/core';
import { CheckInPage } from '../check-in/check-in';
@Component({
templateUrl: 'tabs.html',
})
export class TabsPage {
public tab3Root: any;
constructor() {
this.tab3Root = CheckInPage;
}
}
而現在,我想用它在我TabsPage觀點:
<ion-tabs>
<ion-tab [root]="tab3Root" tabTitle="{{tab3Root.title}}" tabIcon="cog"></ion-tab>
</ion-tabs>
這給了我undefined
當我console.log
它。請協助。
你的代碼看起來不錯。你想要什麼'console.log'? 'this.tab3Root'? – Huiting
@Huiting我只是想從我導入'CheckInPage'的地方訪問'CheckInPage.title'屬性:'TabsPage'。 –
@KaMok,標籤不能像那樣工作。 'tabTitle'屬性只能是一個字符串,所以你需要靜態設置標題。你想稍後改變它,或者你爲什麼要嘗試使用'title'屬性? – sebaferreras