我有一个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