【发布时间】:2017-07-13 17:44:37
【问题描述】:
我试图通过在自己的打字稿文件中定义我的路由模块与另一个模块来分离它。但我收到上述错误:组件是两个模块声明的一部分:AppRoutingModule 和 AppModule
分享以下两个模块:
AppRoutingModule
import { NgModule } from '@angular/core'
import { RouterModule, Routes } from '@angular/router'
import { AdminHomeComponent } from './nav/adminhome.component'
import { UserHomeComponent } from './nav/userhome.component'
import { ContactComponent } from './nav/contact.component'
import { LandingComponent } from './nav/mainhome.component'
import { LoginFormComponent } from './nav/login.component'
const appRoutes: Routes = [
{ path: 'login', component: LoginFormComponent },
{ path: 'adminHome', component: AdminHomeComponent },
{ path: 'userHome', component: UserHomeComponent },
{ path: 'contact', component: ContactComponent },
{ path: '', component: LandingComponent }
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [
RouterModule
]
})
export class AppRoutingModule { }
AppModule
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HttpModule } from '@angular/http';
import { AppRoutingModule} from './app.routing'
import { AdminHomeComponent } from './nav/adminhome.component'
import { UserHomeComponent } from './nav/userhome.component'
import { ContactComponent } from './nav/contact.component'
import { LandingComponent } from './nav/mainhome.component'
import { LoginFormComponent } from './nav/login.component'
import { ShareService } from './nav/ShareService'
//import { PaginationModule } from 'ng2-bootstrap';
//import { Ng2PaginationModule } from 'ng2-pagination';
@NgModule({
imports: [BrowserModule, FormsModule, HttpModule, AppRoutingModule ],
declarations: [AppComponent, AdminHomeComponent, UserHomeComponent, ContactComponent, LandingComponent, LoginFormComponent],
bootstrap: [AppComponent],
providers: [ShareService]
})
export class AppModule { }
我关注了https://angular.io/docs/ts/latest/guide/router.html 路由文档,但遇到了这样的错误。
谁能看看代码中是否存在一些错误。谢谢。
【问题讨论】:
-
错误信息是否说明了两个模块的组成部分是什么?
-
是的。 AdminHomeComponent。
-
这可以在 plunk 中重现吗?
标签: angular module routing components