如何在 ionic 3 中使用选项卡正确设置到我的主应用程序?
How to setroot to my main application with tabs properly in ionic 3?
大家好,我只是用这个命令开始一个项目"ionic start helloWorld tabs"
它生成选项卡式项目,然后我添加一个按钮以推送到新页面,这是我有一个按钮我想回到我的主应用程序,这是我如何编写新页面按钮
newpage.ts
addItem(item: Item) {
this.shopping.addItem(item).then(ref =>{
this.navCtrl.setRoot('TabsPage', {key : ref.key});
})
}
保存项目后,我想返回到我的主要应用程序,我对我的 TabsPage 执行了 setRoot,但我显示了这个错误
invalid link: TabsPage
这是我的 tabs.ts
import { Component } from '@angular/core';
import { AboutPage } from '../about/about';
import { ContactPage } from '../contact/contact';
import { HomePage } from '../home/home';
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root = HomePage;
tab2Root = AboutPage;
tab3Root = ContactPage;
constructor() {
}
}
我错过了什么?我应该导航到 tabspage class 对吗?
UPDATE 在我用 @Yerkon 回答选项二更新我的代码后,我得到了这些错误:
Error: Uncaught (in promise): Error: Type TabsPage is part of the
declarations of 2 modules: AppModule and TabsPageModule! Please
consider moving TabsPage to a higher module that imports AppModule and
TabsPageModule. You can also create a new NgModule that exports and
includes TabsPage then import that NgModule in AppModule and
TabsPageModule. Error: Type TabsPage is part of the declarations of 2
modules: AppModule and TabsPageModule! Please consider moving TabsPage
to a higher module that imports AppModule and TabsPageModule. You can
also create a new NgModule that exports and includes TabsPage then
import that NgModule in AppModule and TabsPageModule.
它说我必须将我的 tabpagemodule 移高,这样做正常吗?或者我错过了什么?
invalid link: TabsPage
抛出此错误,因为 TabsPage 未在模块中注册。
报名方式有两种:
- 如果页面急切加载:
app.module.ts:
@NgModule({
declarations: [
ConferenceApp,
AboutPage,
AccountPage,
LoginPage,
MapPage,
PopoverPage,
SchedulePage,
ScheduleFilterPage,
SessionDetailPage,
SignupPage,
SpeakerDetailPage,
SpeakerListPage,
TabsPage,
TutorialPage,
SupportPage
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(ConferenceApp, {}, {
links: [
{ component: TabsPage, name: 'TabsPage', segment: 'tabs-page' },
...
]
}),
IonicStorageModule.forRoot()
],
...
- 如果页面将延迟加载。在这里为您创建模块的每个页面。
提示:使用 ionic CLI 无需手动创建 page/page.modules。只需 运行:
ionic g page TabsPage
。结果应类似于:
tabs.module.ts:
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { IonicPageModule } from 'ionic-angular';
import { TabsPage } from './tabs';
@NgModule({
declarations: [
TabsPage,
],
imports: [
IonicPageModule.forChild(TabsPage),
],
exports: [
TabsPage
]
})
export class TabsPageModule { }
tabs.ts:
@IonicPage()
@Component({
selector: 'page-tabs',
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root: any = Tab1Root;
tab2Root: any = Tab2Root;
tab3Root: any = Tab3Root;
...
大家好,我只是用这个命令开始一个项目"ionic start helloWorld tabs" 它生成选项卡式项目,然后我添加一个按钮以推送到新页面,这是我有一个按钮我想回到我的主应用程序,这是我如何编写新页面按钮
newpage.ts
addItem(item: Item) {
this.shopping.addItem(item).then(ref =>{
this.navCtrl.setRoot('TabsPage', {key : ref.key});
})
}
保存项目后,我想返回到我的主要应用程序,我对我的 TabsPage 执行了 setRoot,但我显示了这个错误
invalid link: TabsPage
这是我的 tabs.ts
import { Component } from '@angular/core';
import { AboutPage } from '../about/about';
import { ContactPage } from '../contact/contact';
import { HomePage } from '../home/home';
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root = HomePage;
tab2Root = AboutPage;
tab3Root = ContactPage;
constructor() {
}
}
我错过了什么?我应该导航到 tabspage class 对吗?
UPDATE 在我用 @Yerkon 回答选项二更新我的代码后,我得到了这些错误:
Error: Uncaught (in promise): Error: Type TabsPage is part of the declarations of 2 modules: AppModule and TabsPageModule! Please consider moving TabsPage to a higher module that imports AppModule and TabsPageModule. You can also create a new NgModule that exports and includes TabsPage then import that NgModule in AppModule and TabsPageModule. Error: Type TabsPage is part of the declarations of 2 modules: AppModule and TabsPageModule! Please consider moving TabsPage to a higher module that imports AppModule and TabsPageModule. You can also create a new NgModule that exports and includes TabsPage then import that NgModule in AppModule and TabsPageModule.
它说我必须将我的 tabpagemodule 移高,这样做正常吗?或者我错过了什么?
invalid link: TabsPage
抛出此错误,因为 TabsPage 未在模块中注册。 报名方式有两种:
- 如果页面急切加载:
app.module.ts:
@NgModule({
declarations: [
ConferenceApp,
AboutPage,
AccountPage,
LoginPage,
MapPage,
PopoverPage,
SchedulePage,
ScheduleFilterPage,
SessionDetailPage,
SignupPage,
SpeakerDetailPage,
SpeakerListPage,
TabsPage,
TutorialPage,
SupportPage
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(ConferenceApp, {}, {
links: [
{ component: TabsPage, name: 'TabsPage', segment: 'tabs-page' },
...
]
}),
IonicStorageModule.forRoot()
],
...
- 如果页面将延迟加载。在这里为您创建模块的每个页面。
提示:使用 ionic CLI 无需手动创建 page/page.modules。只需 运行:
ionic g page TabsPage
。结果应类似于:
tabs.module.ts:
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { IonicPageModule } from 'ionic-angular';
import { TabsPage } from './tabs';
@NgModule({
declarations: [
TabsPage,
],
imports: [
IonicPageModule.forChild(TabsPage),
],
exports: [
TabsPage
]
})
export class TabsPageModule { }
tabs.ts:
@IonicPage()
@Component({
selector: 'page-tabs',
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root: any = Tab1Root;
tab2Root: any = Tab2Root;
tab3Root: any = Tab3Root;
...