angular - 组件是2个模块声明的一部分:AppModule
问题描述
我正在尝试使用以下链接构建 Basic Ionic SideMenu https://ionicacademy.com/ionic-side-menu-tab-bars/,当我尝试构建时,我遇到了异常,例如错误:未捕获(承诺):错误:类型 DashboardTabsPage 是 2 个模块声明的一部分:AppModule 和 DashboardTabsPageModule!请考虑将 DashboardTabsPage 移至导入 AppModule 和 DashboardTabsPageModule 的更高模块
app.module.ts:
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { DashboardTabsPage } from '../pages/dashboard-tabs/dashboard-tabs';
import { ListsTabsPage } from '../pages/lists-tabs/lists-tabs';
import { NoTabsPage } from '../pages/no-tabs/no-tabs';
@NgModule({
declarations: [
MyApp,
HomePage,
DashboardTabsPage,
ListsTabsPage,
NoTabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
DashboardTabsPage,
ListsTabsPage,
NoTabsPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
app.component.ts:
export class MyApp {
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
}
主页.ts:
import { DashboardTabsPage } from '../dashboard-tabs/dashboard-tabs';
import { ListsTabsPage } from '../lists-tabs/lists-tabs';
import { NoTabsPage } from '../no-tabs/no-tabs';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild(Nav) nav: Nav;
pages: Array<{title: string, component: any}>;
rootPage = 'DashboardTabsPage';
constructor(public navCtrl: NavController) {
this.pages = [
{ title: 'Dashboard', component: DashboardTabsPage },
{ title: 'My Lists', component: ListsTabsPage },
{ title: 'Direkt Profile Link', component: DashboardTabsPage},
{ title: 'No Tabs Link', component: NoTabsPage },
];
}
openPage(page) {
this.nav.setRoot(page.component, { openTab: page.openTab });
}
}
home.ts:
<ion-menu [content]="content">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
解决方案
正如错误所说 "Type DashboardTabsPage is part of the declarations of 2 modules: AppModule and DashboardTabsPageModule!"
,您需要DashboardTabsPage
在app.module.ts 的导入下导出组件DashboardTabsPageModule
并导入。DashboardTabsPageModule
由于您没有DashboardTabsPage
模块,因此您只需从 app.module.ts 中删除它们
@NgModule({
declarations: [
MyApp,
HomePage,
// DashboardTabsPage,
// ListsTabsPage,
// NoTabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
]
推荐阅读
- excel - 使用 Excel VBA For 循环创建多个系列时,为什么第一个系列不反映 .Border.Color 分配?
- vba - 为什么在VBA中粘贴Word表格列大部分时间都会导致错误4605,然后尝试多次成功?
- python - 在文件中查找字符串 A 并使用字符串 A 打印行以及下一行,直到匹配字符串 B
- ssl - Chef apt_repository 开始因 SSL 验证错误而失败
- c# - 如何在 Oracle 身份验证中使用 MS Access 连接字符串
- reactjs - 除非我在 React 中刷新页面,否则状态不会改变
- html - 在自定义滑块 Jquery 上隐藏/显示下一个和上一个按钮
- python - 如何在函数中检测变量赋值?
- typescript - 如果仅定义了字符串,则 Nest.js 验证字符串数组
- reactjs - 为什么 Material-UI 日期与占位符重叠值并抱怨受控输入?