gpt4 book ai didi

angular - 组件是两个模块 :AppRoutingModule and AppModule 声明的一部分

转载 作者:太空狗 更新时间:2023-10-29 17:38:15 25 4
gpt4 key购买 nike

我试图通过在自己的 typescript 文件中定义我的路由模块来将它与另一个模块分开。但是我得到了上面的错误:Component is part of declaration of both the modules:AppRoutingModule and 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 { }

应用模块

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路由文档却遇到这样的错误。

有人可以看看代码中是否存在错误。谢谢。

最佳答案

我认为您应该将 AdminHomeComponentAppRoutingModule 中引用的所有其他组件从 AppModule 中移到不同的模块中,并且将此模块添加到 AppRoutingModuleimports

关于angular - 组件是两个模块 :AppRoutingModule and AppModule 声明的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42412445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com